Re: Trying to write a oo :method that isn't automatically inserted in a namespace.

2007-12-21 Thread Patrick R. Michaud
On Fri, Dec 21, 2007 at 01:30:42AM -0700, Kevin Tew wrote:
 I'm working on http://rt.perl.org/rt3/Ticket/Display.html?id=48631
 I've added parsing of :namespace to imcc, now I'm trying to figure out 
 what I'm suppose to do differently when :namespace is present in a 
 methods prototype.
 I thought I was suppose to add the :method to a namespace, but that 
 seems to already work.

Hmm, you seem to be right.  I could've sworn that I ran into
problems that indicated that :methods weren't automatically going
into the namespace, even as recently as last week, but now I
can't seem to reproduce the problem.  

I think I must have misinterpreted some problem in the past 
as being due to a missing namespace entry, when it may have been
something else.  (Looking in the wrong namespace comes to mind.)
So, it looks like Parrot already does what I need as its current
default behavior.

My apologies for sending you on a false errand, and you have my
gratitude for helping to resolve it so quickly.

Pm


Re: Trying to write a oo :method that isn't automatically inserted in a namespace.

2007-12-21 Thread Allison Randal

On Fri, Dec 21, 2007 at 01:30:42AM -0700, Kevin Tew wrote:
I've added parsing of :namespace to imcc, now I'm trying to figure out 
what I'm suppose to do differently when :namespace is present in a 
methods prototype.
I thought I was suppose to add the :method to a namespace, but that 
seems to already work.


The relevant code is the 'set_pmc_keyed_str' vtable function in 
src/pmc/namespace.pmc. After inserting a method or vtable override, it 
used to skip the rest of the routine and so not insert the namespace 
entry. Not sure when the code changed, but it doesn't particularly matter.


What the code should do is note that the namespace entry was inserted as 
a method or vtable override, maybe by setting an integer flag, and then 
at line 289 check the flag and return if it's true. (It can't just 
return immediately, because some entries are both vtable overrides and 
methods.)


I think I must have misinterpreted some problem in the past 
as being due to a missing namespace entry, when it may have been

something else.  (Looking in the wrong namespace comes to mind.)
So, it looks like Parrot already does what I need as its current
default behavior.


It was set that way in the past, which may have caused an earlier 
problem. But, if you don't actually need the feature now, we won't add 
the flag.


Allison


Re: Trying to write a oo :method that isn't automatically inserted in a namespace.

2007-12-21 Thread Allison Randal

Kevin Tew wrote:


:method subs should not be added to the namespace unless they have a 
:namespace flag.


Yes.

So we should fix set_pmc_keyed_str to not add :methods unless the 
:namespace flag is present.


Sort of. The thing is, 'set_pmc_keyed_str' isn't just storing subs in 
the namespace, it's also storing methods in the class. (Because 
everything defined with '.sub' calls 'set_pmc_keyed_str'.) So, lines 
180-288 of 'set_pmc_keyed_str' are responsible for determining if a sub 
element should be stored somewhere besides the namespace, and lines 290 
onward actually store the sub (or variable) in the namespace.


The whole 'set_pmc_keyed_str' vtable function should be refactored out 
into a series of helper routines. But, refactored or not, what it 
effectively has to do is:


[...] note that the namespace entry was inserted 
as a method or vtable override, maybe by setting an integer flag, and 
then at line 289 check the flag and return if it's true. (It can't 
just return immediately, because some entries are both vtable 
overrides and methods.)


The places where you would currently want to set an I don't belong in 
the namespace flag are lines 199, 217, 242, and 270. (Those are vtable 
override, method, NCI method, and multi method, respectively.)


Allison


Re: Trying to write a oo :method that isn't automatically inserted in a namespace.

2007-12-21 Thread Kevin Tew
Yeah, I spent an hour trying to figure out how 'set_pmc_keyed_str' 
vtable function in src/pmc/namespace.pmc precluded :methods from the 
namespace before I tested it and found out that it didn't.


What do we want the final behavior to be?
I'm going to take a guess, correct me as needed.

:method subs should not be added to the namespace unless they have a 
:namespace flag.


So we should fix set_pmc_keyed_str to not add :methods unless the 
:namespace flag is present.


Kevin


Allison Randal wrote:

On Fri, Dec 21, 2007 at 01:30:42AM -0700, Kevin Tew wrote:
I've added parsing of :namespace to imcc, now I'm trying to figure 
out what I'm suppose to do differently when :namespace is present in 
a methods prototype.
I thought I was suppose to add the :method to a namespace, but that 
seems to already work.


The relevant code is the 'set_pmc_keyed_str' vtable function in 
src/pmc/namespace.pmc. After inserting a method or vtable override, it 
used to skip the rest of the routine and so not insert the namespace 
entry. Not sure when the code changed, but it doesn't particularly 
matter.


What the code should do is note that the namespace entry was inserted 
as a method or vtable override, maybe by setting an integer flag, and 
then at line 289 check the flag and return if it's true. (It can't 
just return immediately, because some entries are both vtable 
overrides and methods.)


I think I must have misinterpreted some problem in the past as being 
due to a missing namespace entry, when it may have been

something else.  (Looking in the wrong namespace comes to mind.)
So, it looks like Parrot already does what I need as its current
default behavior.


It was set that way in the past, which may have caused an earlier 
problem. But, if you don't actually need the feature now, we won't add 
the flag.


Allison