[perl #42300] [PATCH] t/pmc/sub.t: test for creation of lex by clone op

2008-03-16 Thread James Keenan via RT
On Sat Sep 08 07:07:13 2007, bernhard wrote:

 
 As the original issue has been clarified, can I close this ticket?
 

Since no one has suggested otherwise since September, I'll close it for
you :-)

kid51


[perl #42300] [PATCH] t/pmc/sub.t: test for creation of lex by clone op

2007-09-08 Thread Bernhard Schmalhofer via RT
On Do. 26. Apr. 2007, 16:45:08, [EMAIL PROTECTED] wrote:


 Now it makes sense. :) Anyway, I found this by following the Compiler FAQ,
 which says that a new closure should be created by cloning the sub. I
think
 it should be changed to say newclosure, or even explain this (because you
 might really want to clone the Sub in some cases.)

Hi,

in r21136 I have changed compiler_faq.pod, so that it now uses 
'newclosure' instead of 'clone'.
More explanation could also be added to 'examples/tutorial/80_closure.pir'.

As the original issue has been clarified, can I close this ticket?

Regards, 
  Bernhard

-- 
/* [EMAIL PROTECTED] */


Re: [perl #42300] [PATCH] t/pmc/sub.t: test for creation of lex by clone op

2007-04-26 Thread Yehoshua Sapir

On 4/26/07, Matt Diephouse via RT [EMAIL PROTECTED] wrote:


First, the test (rearranged to include only the relevant parts):

+.sub main :main
+.local string ok, not_ok
+ok = ok
+not_ok = not ok
+
+# if 'not ok' is printed, it means that the lexical environment
+# for the first closure in each pair, (where out = ok)
+# was overwritten by the lexical environment created for the
+# second closure (where out = not ok)
+
+$P10 = makebar_clone(ok)
+$P20 = makebar_clone(not_ok)
+$P10()
+.end
+
+.sub makebar_clone
+.param pmc out
+.lex 'out', out
+.const .Sub s = 'bar'
+$P0 = clone s
+.return($P0)
+.end
+
+.sub bar :outer(makebar_clone)
+$P0 = find_lex 'out'
+say $P0
+.end

(This prints not ok. The test in the patch expects ok.)

You're arguing that the different copies of bar that are returned from
makebar_clone
should have different lexical environments. I'm pretty sure that this is
not the case. Without
using newclosure, there's no closure so the lexical environments are the
same.

What the :outer does in this case is rearrange the lexical stack so that
makebar_clone
appears in the lexical stack for bar. So we're using the lexical
environment from the last
time that makebar_clone was called. It's bizarre that this even works
because without the
closure, I'd think that the lexical environment would have destroyed.

I'm not sure how intentional this is. The PDD isn't clear (to me) about
what :outer means in
the absence of newclosure. I'd definitely be interested in seeing why
this would be a useful
feature. More detail in the PDD would be nice.

Thanks for the interesting patch.

--
Matt Diephouse




Now it makes sense. :) Anyway, I found this by following the Compiler FAQ,
which says that a new closure should be created by cloning the sub. I think
it should be changed to say newclosure, or even explain this (because you
might really want to clone the Sub in some cases.)


[perl #42300] [PATCH] t/pmc/sub.t: test for creation of lex by clone op

2007-04-25 Thread Matt Diephouse via RT
First, the test (rearranged to include only the relevant parts):

+.sub main :main
+.local string ok, not_ok
+ok = ok
+not_ok = not ok
+
+# if 'not ok' is printed, it means that the lexical environment
+# for the first closure in each pair, (where out = ok)
+# was overwritten by the lexical environment created for the
+# second closure (where out = not ok)
+
+$P10 = makebar_clone(ok)
+$P20 = makebar_clone(not_ok)
+$P10()
+.end
+
+.sub makebar_clone
+.param pmc out
+.lex 'out', out
+.const .Sub s = 'bar'
+$P0 = clone s
+.return($P0)
+.end
+
+.sub bar :outer(makebar_clone)
+$P0 = find_lex 'out'
+say $P0
+.end

(This prints not ok. The test in the patch expects ok.)

You're arguing that the different copies of bar that are returned from 
makebar_clone 
should have different lexical environments. I'm pretty sure that this is not 
the case. Without 
using newclosure, there's no closure so the lexical environments are the same.

What the :outer does in this case is rearrange the lexical stack so that 
makebar_clone 
appears in the lexical stack for bar. So we're using the lexical environment 
from the last 
time that makebar_clone was called. It's bizarre that this even works because 
without the 
closure, I'd think that the lexical environment would have destroyed.

I'm not sure how intentional this is. The PDD isn't clear (to me) about what 
:outer means in 
the absence of newclosure. I'd definitely be interested in seeing why this 
would be a useful 
feature. More detail in the PDD would be nice.

Thanks for the interesting patch.

--
Matt Diephouse




[perl #42300] [PATCH] t/pmc/sub.t: test for creation of lex by clone op

2007-04-04 Thread Yehoshua Sapir
# New Ticket Created by  Yehoshua Sapir 
# Please include the string:  [perl #42300]
# in the subject line of all future correspondence about this issue. 
# URL: http://rt.perl.org/rt3/Ticket/Display.html?id=42300 



--- t/pmc/sub.t	2007-04-04 17:20:12.0 +0300
+++ t/pmc/sub.new.t	2007-04-04 17:22:18.0 +0300
@@ -7,7 +7,7 @@
 use lib qw( . lib ../lib ../../lib );
 
 use Test::More;
-use Parrot::Test tests = 61;
+use Parrot::Test tests = 62;
 use Parrot::Config;
 
 =head1 NAME
@@ -1379,6 +1379,57 @@
 parrot;Foo;Bar
 OUTPUT
 
+pir_output_is( 'CODE', 'OUTPUT', 'newclosure/clone Sub lex creation' );
+.sub main :main
+$P1 = new .String
+$P1 = 'ok'
+$P2 = new .String
+$P2 = 'not ok'
+
+# if 'not ok' is printed, it means that the lexical environment
+# for the first closure in each pair, (where out = ok)
+# was overwritten by the lexical environment created for the
+# second closure (where out = not ok)
+
+$P10 = makefoo_newclosure($P1)
+$P20 = makefoo_newclosure($P2)
+$P10()
+
+$P10 = makebar_clone($P1)
+$P20 = makebar_clone($P2)
+$P10()
+.end
+
+.sub makefoo_newclosure
+.param pmc out
+.lex 'out', out
+.const .Sub s = 'foo'
+$P0 = newclosure s
+.return($P0)
+.end
+
+.sub makebar_clone
+.param pmc out
+.lex 'out', out
+.const .Sub s = 'foo'
+$P0 = clone s
+.return($P0)
+.end
+
+.sub foo :outer(makefoo_newclosure)
+$P0 = find_lex 'out'
+say $P0
+.end
+
+.sub bar :outer(makebar_clone)
+$P0 = find_lex 'out'
+say $P0
+.end
+CODE
+ok
+ok
+OUTPUT
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4