ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: Nobuyoshi Nakada <nobu@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:18984] Re: [ANN] Ruby 1.9.1 feature freeze
Date: Sat, 27 Sep 2008 03:25:19 +0900	[thread overview]
Message-ID: <20080926182548.B7959E0B4E@mail.bc9.jp> (raw)
In-Reply-To: <966599840809260920u340de0b2m7ee2543549171a39@mail.gmail.com>

Hi,

At Sat, 27 Sep 2008 01:19:37 +0900,
Roger Pack wrote in [ruby-core:18981]:
> >> Yeah I was thinking it would be less confusing to only have one
> >> function name [source_location] and have it apply to both proc and
> >> method.
> >
> > Meanwhile, I added the methods without changing the function
> > names.  The names are another story.
> >
> > # I've thought I'd committed it already, but forgotten.
> 
> Thanks for adding those.  I see them in SVN now.
> I prefer #source_location but #location is livable :)

Methods are #source_location, C functions are still
*_location().

> >> Also note that it was mentioned that Binding#source_location would be
> >> nice--I just have no idea how to add it so the current patch doesn't
> >> include it.
> >
> > What is the line number of Binding?
> 
> There isn't one in that patch.  I'm unsure how to create Binding#source_location

It's easy to implement, if it is OK to return the beginning of
the code block where the binding was made.

\f
Index: proc.c
===================================================================
--- proc.c	(revision 19593)
+++ proc.c	(working copy)
@@ -29,4 +29,5 @@ static VALUE bmcall(VALUE, VALUE);
 static int method_arity(VALUE);
 static VALUE rb_obj_is_method(VALUE m);
+static VALUE iseq_location(rb_iseq_t *iseq);
 
 /* Proc */
@@ -339,4 +340,22 @@ bind_eval(int argc, VALUE *argv, VALUE b
 }
 
+/*
+ * call-seq:
+ *    binding.source_location  => [String, Fixnum]
+ *
+ * returns the ruby source filename and line number containing this binding
+ * or nil if this binding was not defined in ruby (i.e. native)
+ */
+VALUE
+rb_bind_location(VALUE self)
+{
+    rb_binding_t *bind;
+    rb_env_t *env;
+
+    GetBindingPtr(self, bind);
+    GetEnvPtr(bind->env, env);
+    return iseq_location(env->block.iseq);
+}
+
 static VALUE
 proc_new(VALUE klass, int is_lambda)
@@ -1923,4 +1942,5 @@ Init_Binding(void)
     rb_define_method(rb_cBinding, "dup", binding_dup, 0);
     rb_define_method(rb_cBinding, "eval", bind_eval, -1);
+    rb_define_method(rb_cBinding, "source_location", rb_bind_location, 0);
     rb_define_global_function("binding", rb_f_binding, 0);
 }
Index: ruby.c
===================================================================
--- ruby.c	(revision 19593)
+++ ruby.c	(working copy)
@@ -1478,4 +1478,5 @@ ruby_prog_init(void)
 
     rb_define_global_const("ARGV", rb_argv);
+    rb_define_global_const("TOPLEVEL_BINDING", rb_binding_new());
 
 #ifdef MSDOS
Index: vm.c
===================================================================
--- vm.c	(revision 19594)
+++ vm.c	(working copy)
@@ -1241,7 +1241,4 @@ rb_iseq_eval(VALUE iseqval)
     vm_set_top_stack(th, iseqval);
 
-    if (!rb_const_defined(rb_cObject, rb_intern("TOPLEVEL_BINDING"))) {
-	rb_define_global_const("TOPLEVEL_BINDING", rb_binding_new());
-    }
     val = vm_exec(th);
     tmp = iseqval; /* prohibit tail call optimization */
\f

-- 
Nobu Nakada

  reply	other threads:[~2008-09-26 18:27 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <966599840809022308q2d6f4370l1de6340c9f1fee8a@mail.gmail.com>
2008-09-04 16:13 ` [ruby-core:18452] [ANN] Ruby 1.9.1 feature freeze Roger Pack
2008-09-04 17:34   ` [ruby-core:18455] " hemant
2008-09-06 18:38     ` [ruby-core:18469] " Charles Oliver Nutter
2008-09-06 19:53   ` [ruby-core:18471] " Yukihiro Matsumoto
2008-09-06 21:23     ` [ruby-core:18474] " Wilson Bilkovich
2008-09-08  4:02     ` [ruby-core:18487] " Roger Pack
2008-09-08  9:05     ` [ruby-core:18490] " Nobuyoshi Nakada
2008-09-08  9:36       ` [ruby-core:18491] " Yukihiro Matsumoto
2008-09-08 11:22         ` [ruby-core:18493] " Trans
2008-09-09  8:30           ` [ruby-core:18519] " Yukihiro Matsumoto
2008-09-09 23:39             ` [ruby-core:18528] " Trans
2008-09-08 14:41         ` [ruby-core:18496] " Wilson Bilkovich
     [not found]         ` <966599840809080824t69da9db3saec127e89bb6069@mail.gmail.com>
2008-09-08 15:20           ` [ruby-core:18497] " Roger Pack
2008-09-08 18:26             ` [ruby-core:18501] " Wilson Bilkovich
2008-09-09  1:40               ` [ruby-core:18509] " Charles Oliver Nutter
     [not found]               ` <966599840809091113k4c738de3kcfdb74bd747ac1d4@mail.gmail.com>
2008-09-09 18:21                 ` [ruby-core:18521] " Roger Pack
2008-09-10 17:01                   ` [ruby-core:18546] " Paul Brannan
2008-09-16 20:10                   ` [ruby-core:18636] " Roger Pack
2008-09-08 15:24         ` [ruby-core:18498] " Robert Klemme
2008-09-08 19:27           ` [ruby-core:18502] " Joel VanderWerf
2008-09-20 18:49       ` [ruby-core:18763] " Roger Pack
2008-09-25  1:18         ` [ruby-core:18875] " Nobuyoshi Nakada
     [not found]         ` <966599840809251625t77060aedq4248037a6c95cc84@mail.gmail.com>
2008-09-26  4:17           ` [ruby-core:18970] " Roger Pack
2008-09-26 14:09             ` [ruby-core:18978] " Nobuyoshi Nakada
2008-09-26 16:19               ` [ruby-core:18981] " Roger Pack
2008-09-26 18:25                 ` Nobuyoshi Nakada [this message]
2008-12-19 21:55       ` [ruby-core:20708] " Roger Pack

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080926182548.B7959E0B4E@mail.bc9.jp \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).