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_ic                    1216
 stm_abort                      1217
 stm_depth_i                    1218
+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 B<clone>(out PMC, invar PMC)
 
 Makes a copy of the PMC in $2 and puts it in $1.
@@ -526,7 +525,6 @@
   goto NEXT();
 }
 
-
 =item B<clone>(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 B<copy>(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

Reply via email to