Google 网上论坛不再支持新的 Usenet 帖子或订阅项。历史内容仍可供查看。

[perl #41790] [PATCH] Change sub's get_string to return short name

已查看 10 次
跳至第一个未读帖子

Will Coleda

未读,
2007年3月12日 01:24:152007/3/12
收件人 bugs-bi...@rt.perl.org
# New Ticket Created by Will Coleda
# Please include the string: [perl #41790]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=41790 >


I have some work for Tcl pending commit that requires I know the name
a .Sub was invoked with at runtime, so I need a way to get at the
name at runtime. Currently, the following code (jisom++)

.sub main :main
'foo'()
.end

.sub 'foo'
print "We're inside sub "
$P0 = interpinfo 14
$S0 = $P0
say $S0
.end

says 'parrot;foo'. While I could strip off the leading namespace,
this would fail for subs like:

.sub 'foo;bar'
...
.end

And, even if we fixed the semi-predicate problem during the
stringification, stripping out the information needed will be even
harder.

So, since we can we can already get the current namespace with:

current_ns = interp['namespace']

I vote we change Sub's get_string to return the simple name instead
of the full name.

Below is a patch to do just that (mdiep++). Hearing no objections
(anyone?), I'd like to get this into 0.4.10.

With it applied, there are ~13 core subtest failures, those will need
to be fixed to expect the new behavior.

=== src/pmc/sub.pmc
==================================================================
--- src/pmc/sub.pmc (revision 4399)
+++ src/pmc/sub.pmc (local)
@@ -120,7 +120,8 @@
*/
STRING* get_string() {
- return Parrot_full_sub_name(INTERP, SELF);
+ struct Parrot_sub * const sub = PMC_sub(SELF);
+ return Parrot_make_COW_reference(INTERP, sub->name);
}
void set_string_native(STRING *subname) {

--
Will "Coke" Coleda
wi...@coleda.com


Jonathan Worthington

未读,
2007年3月12日 06:12:342007/3/12
收件人 perl6-i...@perl.org
Will Coleda (via RT) wrote:
> I have some work for Tcl pending commit that requires I know the name
> a .Sub was invoked with at runtime, so I need a way to get at the
> name at runtime. Currently, the following code (jisom++)
>
> .sub main :main
> 'foo'()
> .end
>
> .sub 'foo'
> print "We're inside sub "
> $P0 = interpinfo 14
> $S0 = $P0
> say $S0
> .end
>
> says 'parrot;foo'. While I could strip off the leading namespace,
> this would fail for subs like:
>
> .sub 'foo;bar'
> ...
> .end
>
> And, even if we fixed the semi-predicate problem during the
> stringification, stripping out the information needed will be even
> harder.
>
Yup, agree with this, but...

> So, since we can we can already get the current namespace with:
>
> current_ns = interp['namespace']
>

This isn't a full replacement of the functionality we'd "lose", since
you may want to get the namespace of a sub other than the one you're
currently executing. There may already be a way to do that, though...if
not, maybe the sub PMC needs a get_namespace method.

> I vote we change Sub's get_string to return the simple name instead
> of the full name.

Gets my vote too.

>
> Below is a patch to do just that (mdiep++). Hearing no objections
> (anyone?), I'd like to get this into 0.4.10.
>
> With it applied, there are ~13 core subtest failures, those will need
> to be fixed to expect the new behavior.
>

Just to be clear - are they tests of what Sub stringifies to rather than
failures as a result of other bits of the core expecting Sub to
stringify to something including the namespace? Not that both can't be
fixed, just curious.

Jonathan


Matt Diephouse

未读,
2007年3月12日 10:52:302007/3/12
收件人 Jonathan Worthington、perl6-i...@perl.org
Jonathan Worthington <jona...@jwcs.net> wrote:
>
> Will Coleda (via RT) wrote:
> > So, since we can we can already get the current namespace with:
> >
> > current_ns = interp['namespace']
> >
> This isn't a full replacement of the functionality we'd "lose", since
> you may want to get the namespace of a sub other than the one you're
> currently executing. There may already be a way to do that, though...if
> not, maybe the sub PMC needs a get_namespace method.


Actually, it already has one.

> I vote we change Sub's get_string to return the simple name instead
> > of the full name.
> Gets my vote too.


Mine too. I almost changed this myself a couple weeks ago.

>
> > Below is a patch to do just that (mdiep++). Hearing no objections
> > (anyone?), I'd like to get this into 0.4.10.
> >
> > With it applied, there are ~13 core subtest failures, those will need
> > to be fixed to expect the new behavior.
> >
> Just to be clear - are they tests of what Sub stringifies to rather than
> failures as a result of other bits of the core expecting Sub to
> stringify to something including the namespace? Not that both can't be
> fixed, just curious.
>

There's some of both, I think. I recently had to change a test to expect the
long name of a Sub because there was no way to get the short name.

--
Matt Diephouse
http://matt.diephouse.com

Allison Randal

未读,
2007年3月13日 14:50:192007/3/13
收件人 ma...@diephouse.com、Jonathan Worthington、perl6-i...@perl.org
Matt Diephouse wrote:
> Jonathan Worthington <jona...@jwcs.net> wrote:
>>
>> Will Coleda (via RT) wrote:
>> > So, since we can we can already get the current namespace with:
>> >
>> > current_ns = interp['namespace']
>> >
>> This isn't a full replacement of the functionality we'd "lose", since
>> you may want to get the namespace of a sub other than the one you're
>> currently executing. There may already be a way to do that, though...if
>> not, maybe the sub PMC needs a get_namespace method.
>
> Actually, it already has one.
>
>> I vote we change Sub's get_string to return the simple name instead
>> > of the full name.
>> Gets my vote too.
>
> Mine too. I almost changed this myself a couple weeks ago.

Approved. When applying the patch, make sure Sub's get_namespace method
is documented and tested.

Allison

Matt Diephouse via RT

未读,
2007年3月15日 00:50:162007/3/15
收件人 perl6-i...@perl.org
Applied in r17484 with updated tests and a test for the get_namespace() method.
0 个新帖子