cvsuser 04/08/29 16:01:57
Modified: classes undef.pmc
t/pmc undef.t
Log:
Fixed get_bool vtable entry and a bunch of tests
Courtesy of Bernhard Schmalhofer <[EMAIL PROTECTED]>
Revision Changes Path
1.9 +9 -12 parrot/classes/undef.pmc
Index: undef.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/undef.pmc,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -r1.8 -r1.9
--- undef.pmc 17 Aug 2004 09:16:15 -0000 1.8
+++ undef.pmc 29 Aug 2004 23:01:55 -0000 1.9
@@ -1,6 +1,6 @@
/*
Copyright: 2004 The Perl Foundation. All Rights Reserved.
-$Id: undef.pmc,v 1.8 2004/08/17 09:16:15 leo Exp $
+$Id: undef.pmc,v 1.9 2004/08/29 23:01:55 dan Exp $
=head1 NAME
@@ -8,11 +8,12 @@
=head1 DESCRIPTION
-Parrot's generic undef type. This pmc has no defined value. It returns a
-numeric value of 0, a boolean of false, and an empty string. When assigned
-a number, integer, or string it morphs to a Number, Integer, or String PMC
-respectively, and when assigned a generic PMC it morphs into a PMC of the
-passed-in type and does a same-type assignment from there.
+This is Parrot's generic undef type. This PMC has no defined value.
+It returns a numeric value of 0, a boolean of false, and an empty string.
+When assigned a number, integer, or string it morphs to a Number,
+Integer, or String PMC respectively, and when assigned a generic PMC
+it morphs into a PMC of the passed-in type and does a same-type assignment
+from there.
=head2 Methods
@@ -72,16 +73,12 @@
VTABLE_set_string_native(INTERP, SELF, value);
}
- BOOLVAL get_boolean() {
+ INTVAL get_bool() {
return 0;
}
- void set_boolean(BOOLVAL value) {
- VTABLE_morph(INTERP, SELF, enum_class_Boolean);
- VTABLE_set_boolean(INTERP, SELF, value);
}
-}
/*
=back
1.3 +145 -2 parrot/t/pmc/undef.t
Index: undef.t
===================================================================
RCS file: /cvs/public/parrot/t/pmc/undef.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -r1.2 -r1.3
--- undef.t 22 Aug 2004 09:15:52 -0000 1.2
+++ undef.t 29 Aug 2004 23:01:57 -0000 1.3
@@ -1,6 +1,6 @@
#! perl -w
# Copyright: 2001-2004 The Perl Foundation. All Rights Reserved.
-# $Id: undef.t,v 1.2 2004/08/22 09:15:52 leo Exp $
+# $Id: undef.t,v 1.3 2004/08/29 23:01:57 dan Exp $
=head1 NAME
@@ -16,7 +16,7 @@
=cut
-use Parrot::Test tests => 2;
+use Parrot::Test tests => 8;
use Test::More qw(skip);
output_is(<<'CODE', <<'OUTPUT', "morph to string");
@@ -31,6 +31,149 @@
foofoo
OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', "get_bool");
+##PIR##
+.sub _main
+ .local pmc pmc1
+ pmc1 = new Undef
+ print "A PMC Undef created by new is"
+ if pmc1 goto PMC1_IS
+ print " not"
+ PMC1_IS:
+ print "\n"
+ end
+.end
+CODE
+A PMC Undef created by new is not
+OUTPUT
+
+
+output_is(<<'CODE', <<'OUTPUT', "defined");
+##PIR##
+.sub _main
+ .local pmc pmc1
+ pmc1 = new Undef
+ .local int is_defined
+ is_defined = defined pmc1
+ print "A PMC Undef is"
+ if is_defined goto PMC1_IS_DEFINED
+ print " not"
+ PMC1_IS_DEFINED:
+ print " defined.\n"
+ end
+.end
+CODE
+A PMC Undef is not defined.
+OUTPUT
+
+
+output_is(<<'CODE', <<'OUTPUT', "get_string");
+##PIR##
+.sub _main
+ .local pmc pmc1
+ pmc1 = new Undef
+ print "before"
+ print pmc1
+ print "after\n"
+ end
+.end
+CODE
+beforeafter
+OUTPUT
+
+
+output_is(<<'CODE', <<'OUTPUT', "morph to integer");
+##PIR##
+.sub _main
+ .local pmc pmc1
+ pmc1 = new Undef
+ .local int int1
+ int1 = pmc1
+ .local int int2
+ int2 = -7777777
+ int2 += int1
+ print int2
+ print "\n"
+ end
+.end
+CODE
+-7777777
+OUTPUT
+
+
+output_is(<<'CODE', <<'OUTPUT', "morph to float");
+##PIR##
+.sub _main
+ .local pmc pmc1
+ pmc1 = new Undef
+ .local int int1
+ int1 = pmc1
+ .local num float1
+ float1 = -7777777e-3
+ float1 += int1
+ print float1
+ print "\n"
+ end
+.end
+CODE
+-7777.777000
+OUTPUT
+
+
+output_is(<<'CODE', <<'OUTPUT', "isa");
+##PIR##
+.sub _main
+ .local pmc pmc1
+ pmc1 = new Undef
+ .local int pmc1_is_a
+
+ pmc1_is_a = isa pmc1, "Undef"
+ print "A Undef PMC is "
+ if pmc1_is_a goto PMC1_IS_A_Undef
+ print "not "
+ PMC1_IS_A_Undef:
+ print "a Undef.\n"
+
+ pmc1_is_a = isa pmc1, "default"
+ print "A Undef PMC is "
+ if pmc1_is_a goto PMC1_IS_A_default
+ print "not "
+ PMC1_IS_A_default:
+ print "a default.\n"
+
+ pmc1_is_a = isa pmc1, "Default"
+ print "A Undef PMC is "
+ if pmc1_is_a goto PMC1_IS_A_Default
+ print "not "
+ PMC1_IS_A_Default:
+ print "a Default.\n"
+
+ pmc1_is_a = isa pmc1, "scalar"
+ print "A Undef PMC is "
+ if pmc1_is_a goto PMC1_IS_A_scalar
+ print "not "
+ PMC1_IS_A_scalar:
+ print "a scalar.\n"
+
+ pmc1_is_a = isa pmc1, "Scalar"
+ print "A Undef PMC is "
+ if pmc1_is_a goto PMC1_IS_A_Scalar
+ print "not "
+ PMC1_IS_A_Scalar:
+ print "a Scalar.\n"
+
+ end
+.end
+CODE
+A Undef PMC is a Undef.
+A Undef PMC is not a default.
+A Undef PMC is not a Default.
+A Undef PMC is not a scalar.
+A Undef PMC is not a Scalar.
+OUTPUT
+
+
output_is(<< 'CODE', << 'OUTPUT', "check wether interface is done");
##PIR##
.sub _main