Author: mdiep
Date: Thu Jan 25 17:50:45 2007
New Revision: 16798

Modified:
   trunk/src/pmc/sub.pmc
   trunk/t/pmc/sub.t

Log:
Implement the Sub PMC's assign_pmc vtable function

Modified: trunk/src/pmc/sub.pmc
==============================================================================
--- trunk/src/pmc/sub.pmc       (original)
+++ trunk/src/pmc/sub.pmc       Thu Jan 25 17:50:45 2007
@@ -351,6 +351,34 @@
 
 /*
 
+=item C<void assign_pmc(PMC* other)>
+
+Set SELF to the data in other.
+
+=cut
+
+*/
+
+    void set_pmc(PMC* other) {
+        DYNSELF.assign_pmc(other);
+    }
+
+    void assign_pmc(PMC* other) {
+        /* only handle the case where the other PMC is a Sub */
+        if (other->vtable->base_type == enum_class_Sub) {
+            /* copy the sub struct */
+            memcpy(PMC_sub(SELF), PMC_sub(other), sizeof (struct Parrot_sub));
+            /* copy the name so it's a different string in memory */
+            PMC_sub(SELF)->name = string_copy(INTERP, PMC_sub(SELF)->name);
+        }
+        else {
+            real_exception(INTERP, NULL, E_TypeError,
+                           "Can't assign a non-Sub type to a Sub");
+        }
+    }
+
+/*
+
 =item C<void mark()>
 
 Marks the sub as live.

Modified: trunk/t/pmc/sub.t
==============================================================================
--- trunk/t/pmc/sub.t   (original)
+++ trunk/t/pmc/sub.t   Thu Jan 25 17:50:45 2007
@@ -7,7 +7,7 @@
 use lib qw( . lib ../lib ../../lib );
 
 use Test::More;
-use Parrot::Test tests => 58;
+use Parrot::Test tests => 59;
 use Parrot::Config;
 
 =head1 NAME
@@ -1319,6 +1319,23 @@
 main
 OUTPUT
 
+pir_output_is(<<'CODE', <<'OUTPUT', 'assign');
+.sub main :main
+    $P0 = get_global 'ok'
+
+    $P1 = new .Undef
+    assign $P1, $P0
+
+    $P1()
+.end
+
+.sub ok
+    say "ok"
+.end
+CODE
+ok
+OUTPUT
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4

Reply via email to