There are a number of set ops documented in core.ops that haven't
 actually been implemented - conversion from STR to INT/NUM (and 
 vice versa), plus conversion from PMCs to STR. 

 The enclosed patch implements the last of these, and adds tests for
 PerlUndefs and  PerlStrings (and implicitly PerlInts and PerlNums -
 should we also add explicit tests for these?). I haven't added tests
 for arrays/hashes, as I'm unclear what, if anything, they should 
 actually be returning in this context.

 Simon


--- core.ops.old        Fri Feb  1 15:57:44 2002
+++ core.ops    Fri Feb  1 15:59:10 2002
@@ -527,6 +527,11 @@
   goto NEXT();
 }
 
+inline op set(out STR, in PMC) {
+  $1 = $2->vtable->get_string(interpreter, $2);
+  goto NEXT();
+}
+
 inline op set(out STR, in STR) {
   $1 = string_copy(interpreter, $2);
   goto NEXT();


--- t/pmc/perlstring.t.old      Fri Feb  1 17:48:25 2002
+++ t/pmc/perlstring.t  Fri Feb  1 18:47:13 2002
@@ -1,6 +1,49 @@
 #! perl -w
 
-use Parrot::Test tests => 5;
+use Parrot::Test tests => 6;
+
+output_is(<<CODE, <<OUTPUT, "Set/get strings");
+        new P0, PerlString
+        set P0, "foo"
+        set S0, P0
+        print P0
+        print "\\n"
+        print S0
+        print "\\n"
+
+        set P0, "\0"
+        set S0, P0
+        print P0
+        print S0
+
+        set P0, ""
+        set S0, P0
+        print P0
+        print S0
+
+        set P0, 123
+        set S0, P0
+        print P0
+        print "\\n"
+        print S0
+        print "\\n"
+
+        set P0, 1.234567
+        set S0, P0
+        print P0
+        print "\\n"
+        print S0
+        print "\\n"
+
+        end
+CODE
+foo
+foo
+123
+123
+1.234567
+1.234567
+OUTPUT
 
 output_is(<<CODE, <<OUTPUT, "ensure that concat ppp copies strings");
        new P0, PerlString

--- t/pmc/pmc.t.old     Fri Feb  1 18:26:51 2002
+++ t/pmc/pmc.t  Fri Feb  1 18:28:24 2002
@@ -1,6 +1,6 @@
 #! perl -w
 
-use Parrot::Test tests => 58;
+use Parrot::Test tests => 59;
 use Test::More;
 
 my $fp_equality_macro = <<'ENDOFMACRO';
@@ -558,6 +558,7 @@
        set     I0, P0
        print   I0
        print   "\\n"
+       end
 CODE
 1Z1
 1
@@ -1254,6 +1255,14 @@
 0
 0
 OUTPUT
+
+output_is(<<"CODE", <<'OUTPUT', "undef-string");
+       new P0, PerlUndef
+        set S0, P0
+       end
+CODE
+OUTPUT
+
 
 output_is(<<CODE, <<OUTPUT, "IntQueue test");
        new P0,IntQueue

Reply via email to