Re: [perl #47828] [TODO] Implement the 'copy' opcode
On Sun, Apr 13, 2008 at 09:05:38AM -0700, Bernhard Schmalhofer via RT wrote: On Mi. 19. Mär. 2008, 07:38:36, pmichaud wrote: On Thu Dec 13 17:47:05 2007, [EMAIL PROTECTED] wrote: Implement a 'copy' assignment (at least until we get the 'copy' opcode -- see RT#47828). The copy opcode has been added in r23917. Can this ticket be resolved now? Short answer: yes. Longer: I was waiting to close this ticket until we had confirmation that it was working for Rakudo and PCT. Jonathan submitted a patch yesterday that has it working for Rakudo, so I think we can now close the ticket. Thanks! Pm
Re: [perl #47828] [TODO] Implement the 'copy' opcode
On Mon, Mar 17, 2008 at 10:26:21AM -0700, Will Coleda via RT wrote: compilers/pct/src/PAST/Compiler.pir says: On Thu Dec 13 17:47:05 2007, [EMAIL PROTECTED] wrote: Implement a 'copy' assignment (at least until we get the 'copy' opcode -- see RT#47828). Now that the copy op is implemented, this should be implementable. I tried implementing this a couple of weeks ago (pre-pdd17 merge) and ran into a couple of problems. I decided to hold off on it until after the pdd17 merge and simply haven't had a chance to try it again. Pm
Re: [perl #47828] [TODO] Implement the 'copy' opcode
On Tuesday 11 December 2007 20:41:08 chromatic wrote: Here's a first step. I added a stripped-down version of the code in RT #48467 as a second test, and it fails for me with: set_pmc() not implemented in class 'Num' I tried to debug it, but I have what they call Stupid Fingers tonight, and as such can't tell if I need to add assign_pmc() to Class, Object, or PMCProxy, or just go take a nap. Also holophoner lessons. This snail is just grumpy enough. -- c === MANIFEST == --- MANIFEST (revision 23869) +++ MANIFEST (local) @@ -3313,6 +3313,7 @@ t/op/cc_state.t [] t/op/cmp-nonbranch.t[] t/op/comp.t [] +t/op/copy.t [] t/op/debuginfo.t[] t/op/exceptions.t [] t/op/gc.t [] === PBC_COMPAT == --- PBC_COMPAT (revision 23869) +++ PBC_COMPAT (local) @@ -28,6 +28,7 @@ # please insert tab separated entries at the top of the list +3.09 2007.12.13 chromatic added copy_p_p opcode 3.08 2007.12.12 allison added addhandler_p opcode 3.07 2007.12.12 tewk added die_s die_sc die_p die_pc opcodes 3.06 2007.11.28 coke remove classname opcode === src/ops/ops.num == --- src/ops/ops.num (revision 23869) +++ src/ops/ops.num (local) @@ -945,309 +945,310 @@ clone_p_p 915 clone_p_p_p 916 clone_p_p_pc917 -null_s 918 -null_i 919 -null_p 920 -null_n 921 -cleari 922 -clearn 923 -clears 924 -clearp 925 -saveall 926 -restoreall 927 -entrytype_i_i 928 -entrytype_i_ic 929 -depth_i 930 -lookback_i_i931 -lookback_i_ic 932 -lookback_s_i933 -lookback_s_ic 934 -lookback_n_i935 -lookback_n_ic 936 -lookback_p_i937 -lookback_p_ic 938 -save_i 939 -save_ic 940 -save_n 941 -save_nc 942 -save_p 943 -save_s 944 -save_sc 945 -savec_s 946 -savec_sc947 -restore_i 948 -restore_n 949 -restore_p 950 -restore_s 951 -rotate_up_i 952 -rotate_up_ic953 -ord_i_s 954 -ord_i_sc955 -ord_i_s_i 956 -ord_i_sc_i 957 -ord_i_s_ic 958 -ord_i_sc_ic 959 -chr_s_i 960 -chr_s_ic961 -chopn_s_i 962 -chopn_s_ic 963 -chopn_s_s_i 964 -chopn_s_sc_i965 -chopn_s_s_ic966 -chopn_s_sc_ic 967 -concat_s_s 968 -concat_s_sc 969 -concat_s_s_s970 -concat_s_sc_s 971 -concat_s_s_sc 972 -concat_s_sc_sc 973 -repeat_s_s_i974 -repeat_s_sc_i 975 -repeat_s_s_ic 976 -repeat_s_sc_ic 977 -length_i_s 978 -length_i_sc 979 -bytelength_i_s 980 -bytelength_i_sc 981 -pin_s 982 -unpin_s 983 -substr_s_s_i984 -substr_s_sc_i 985 -substr_s_s_ic 986 -substr_s_sc_ic 987 -substr_s_s_i_i 988 -substr_s_sc_i_i 989 -substr_s_s_ic_i 990 -substr_s_sc_ic_i991 -substr_s_s_i_ic 992 -substr_s_sc_i_ic993 -substr_s_s_ic_ic994 -substr_s_sc_ic_ic 995 -substr_s_s_i_i_s996 -substr_s_s_ic_i_s 997 -substr_s_s_i_ic_s 998 -substr_s_s_ic_ic_s 999 -substr_s_s_i_i_sc 1000 -substr_s_s_ic_i_sc 1001 -substr_s_s_i_ic_sc 1002 -substr_s_s_ic_ic_sc1003 -substr_s_i_i_s
Re: [perl #47828] [TODO] Implement the 'copy' opcode
On Tuesday 11 December 2007 12:35:19 Allison Randal via RT wrote: Task description: Add an opcode 'copy' to src/ops/set.ops. Similar to 'clone'. - It takes two PMC arguments - It calls VTABLE_morph on $1, and then VTABLE_assign on the two. - It needs to call VTABLE_type to get the type of the source PMC to pass to 'morph' instead of calling $1-vtable-base_type, because the base_type won't be right for Object PMCs. Here's a first step. I added a stripped-down version of the code in RT #48467 as a second test, and it fails for me with: set_pmc() not implemented in class 'Num' I tried to debug it, but I have what they call Stupid Fingers tonight, and as such can't tell if I need to add assign_pmc() to Class, Object, or PMCProxy, or just go take a nap. Also holophoner lessons. -- c === MANIFEST == --- MANIFEST (revision 23776) +++ MANIFEST (local) @@ -3262,6 +3262,7 @@ t/op/cc_state.t [] t/op/cmp-nonbranch.t[] t/op/comp.t [] +t/op/copy.t [] t/op/debuginfo.t[] t/op/exceptions.t [] t/op/gc.t [] === src/ops/ops.num == --- src/ops/ops.num (revision 23776) +++ src/ops/ops.num (local) @@ -1246,3 +1246,4 @@ stm_wait_ic1216 stm_abort 1217 stm_depth_i1218 +copy_p_p 1219 === src/ops/set.ops == --- src/ops/set.ops (revision 23776) +++ src/ops/set.ops (local) @@ -514,7 +514,6 @@ goto NEXT(); } - =item Bclone(out PMC, invar PMC) Makes a copy of the PMC in $2 and puts it in $1. @@ -526,7 +525,6 @@ goto NEXT(); } - =item Bclone(out PMC, invar PMC, in PMC) Makes a copy of the PMC in $2 and puts it in $1, using the arguments in $3. @@ -538,6 +536,19 @@ goto NEXT(); } +=item Bcopy(inout PMC, invar PMC) + +Morphs the PMC in $1 to the type of the PMC in $2, then assigns $2 to $1. + +=cut + +inline op copy(inout PMC, invar PMC) :base_mem { + INTVAL type = VTABLE_type(interp, $2); + VTABLE_morph(interp, $1, type); + VTABLE_assign_pmc(interp, $1, $2); + goto NEXT(); +} + =back =cut === t/op/copy.t == --- t/op/copy.t (revision 23776) +++ t/op/copy.t (local) @@ -0,0 +1,64 @@ +#! parrot +# Copyright (C) 2007, The Perl Foundation. +# $Id: /mirror/trunk/t/op/say.t 20627 2007-08-14T23:50:55.898359Z chromatic $ + +=head1 NAME + +t/op/copy - Testing the copy opcode + +=head1 SYNOPSIS + +% prove t/op/copy.t + +=head1 DESCRIPTION + +Tests various PMCs with copy. + +=cut + +.sub 'main' :main +.include 'include/test_more.pir' + +plan(3) + +test_basic() +test_rt48467() +.end + +.sub 'test_basic' +.local pmc dest +dest = new 'Integer' +dest = 2 + +.local pmc src +src = new 'Float' +src = 1.28 + +dest = copy src +isa_ok( dest, 'Float', 'copy should change type of PMC' ) +is( dest, 1.28, '... and its value' ) +.end + +.sub 'test_rt48467' +.local pmc my_float +my_float = subclass 'Float', 'Num' + +## my $x = 0; +.local pmc dest +dest = new 'Integer' +dest = 0 + +## my $y = 3.2; +.local pmc src +src = new 'Num' +src = 3.2 + +## $x = $y; +dest = copy src + +## $y++; +inc src + +## say '$x = ', $x; +is( dest, 3.2, 'copy should make independent copies' ) +.end
Re: [perl #47828] [TODO] Implement the 'copy' opcode
Patrick R. Michaud via RT wrote: The opcode will be implemented by calling the 'morph' and 'assign' vtable functions. Just a note that there are a lot of the built-in types -- especially the aggregate and subroutine types -- that don't currently have implementations of 'assign'. This is why I've been favoring solutions that somehow use clone instead of morph+assign . The 'assign' vtable entry currently defaults to calling the 'set' vtable entry, which kind of defeats the purpose of first reclaiming the existing PMC header. With the implementation of PDD 17, we can set up a saner default implementation of 'assign', since the majority of PMCs will be storing their core information in the data struct. It won't be much work to add a custom 'assign' vtable entry to the few PMCs that don't use the standard. Allison
Re: [perl #47828] [TODO] Implement the 'copy' opcode
On Mon, Nov 26, 2007 at 01:03:32AM -0800, Allison Randal wrote: The 'copy' opcode is similar to 'clone' but it reuses the PMC header of the destination register. It takes two PMC arguments. The opcode will be implemented by calling the 'morph' and 'assign' vtable functions. Just a note that there are a lot of the built-in types -- especially the aggregate and subroutine types -- that don't currently have implementations of 'assign'. This is why I've been favoring solutions that somehow use clone instead of morph+assign . Pm assign implemented. Allison
Re: [perl #47828] [TODO] Implement the 'copy' opcode
On Mon, Nov 26, 2007 at 09:03:38AM -0600, Patrick R. Michaud wrote: On Mon, Nov 26, 2007 at 01:03:32AM -0800, Allison Randal wrote: The 'copy' opcode is similar to 'clone' but it reuses the PMC header of the destination register. It takes two PMC arguments. The opcode will be implemented by calling the 'morph' and 'assign' vtable functions. Just a note that there are a lot of the built-in types -- especially the aggregate and subroutine types -- that don't currently have implementations of 'assign'. This is why I've been favoring solutions that somehow use clone instead of morph+assign . On the other hand, since the primary reason for having a 'copy' opcode is to be able to implement variations of 'assign', using 'morph' and 'assign' vtable functions might be more accurate. So, I'm not as much in favor of using clone as before, and will leave it up to wiser heads and implementors to decide. :-) Pm