tagged release 0.7.1
[parrot.git] / src / pmc / undef.pmc
blob4e11a71dcd9e92fa4b41614fd46d983c087bbc8b
1 /*
2 Copyright (C) 2004 - 2008, The Perl Foundation.
3 $Id$
5 =head1 NAME
7 src/pmc/undef.pmc - Generic undefined value
9 =head1 DESCRIPTION
11 This is Parrot's generic undef type. This PMC has no defined value.
12 It returns a numeric value of 0, a boolean of false, and an empty string.
13 When assigned a number, integer, or string it morphs to a Number,
14 Integer, or String PMC respectively, and when assigned a generic PMC
15 it morphs into a PMC of the passed-in type and does a same-type assignment
16 from there.
18 =head2 Methods
20 =over 4
22 =cut
26 #include "parrot/parrot.h"
27 #define UNDEF_STRING_CLASS enum_class_String
29 pmclass Undef extends default no_ro {
33 =item C<void set_pmc(PMC *other)>
35 Sets the current PMC to C<*other> by first changing the current PMC to the
36 appropriate type.
38 =cut
42     VTABLE void set_pmc(PMC *other) {
43         VTABLE_morph(INTERP, SELF, enum_class_Ref);
44         VTABLE_set_pmc(INTERP, SELF, other);
45     }
49 =item C<void assign_pmc(PMC *other)>
51 Assigns the PMC to the value of C<*other> by first changing the PMC to the
52 appropriate type.
54 =cut
58     VTABLE void assign_pmc(PMC *other) {
59         if (!PObj_is_object_TEST(other))
60             VTABLE_morph(INTERP, SELF, other->vtable->base_type);
62         /* don't want to call set_pmc if we're assigning an Undef to an Undef */
63         if (other->vtable->base_type != enum_class_Undef)
64             VTABLE_set_pmc(INTERP, SELF, other);
65     }
70 =item C<INTVAL get_integer()>
72 Returns 0.
74 =cut
78     VTABLE INTVAL get_integer() {
79         return 0;
80     }
84 =item C<INTVAL defined()>
86 Returns 0.
88 =cut
92     VTABLE INTVAL defined() {
93         return 0;
94     }
98 =item C<void set_integer_native(INTVAL value)>
100 Morphs the current PMC to an C<Integer> and sets the value from C<value>.
102 =cut
106     VTABLE void set_integer_native(INTVAL value) {
107         VTABLE_morph(INTERP, SELF, enum_class_Integer);
108         VTABLE_set_integer_native(INTERP, SELF, value);
109     }
113 =item C<FLOATVAL get_number()>
115 Returns 0.0.
117 =cut
121     VTABLE FLOATVAL get_number() {
122         return 0.0;
123     }
127 =item C<void set_number_native(FLOATVAL value)>
129 Morphs the current PMC to a C<Float> and sets the value from C<value>.
131 =cut
135     VTABLE void set_number_native(FLOATVAL value) {
136         VTABLE_morph(INTERP, SELF, enum_class_Float);
137         VTABLE_set_number_native(INTERP, SELF, value);
138     }
142 =item C<STRING *get_string()>
144 Returns an empty string.
146 =cut
150     VTABLE STRING *get_string() {
151         return string_make_empty(INTERP, enum_stringrep_one, 0);
152     }
156 =item C<void set_string_native(STRING *value)>
158 Morphs the current PMC to a C<String> and sets the value from C<value>.
160 =cut
164     VTABLE void set_string_native(STRING *value) {
165         VTABLE_morph(INTERP, SELF, UNDEF_STRING_CLASS);
166         VTABLE_set_string_native(INTERP, SELF, value);
167     }
171 =item C<INTVAL get_bool()>
173 Returns 0.
175 =cut
179     VTABLE INTVAL get_bool() {
180         return 0;
181     }
185 =item C<void share()>
187 Unknown. (TODO)
189 =cut
193     VTABLE void share() {
194         /* see src/pmc/integer.pmc */
195     }
199 =item C<PMC *share_ro()>
201 Unknown. (TODO)
203 =cut
207     VTABLE PMC *share_ro() {
208         if (PObj_is_PMC_shared_TEST(SELF))
209             return SELF;
210         else
211             return pt_shared_fixup(INTERP, SELF);
212     }
216 =item C<PMC *clone()>
218 Clones the current Undef PMC.
220 =cut
224     VTABLE PMC *clone() {
225         return pmc_new(INTERP, SELF->vtable->base_type);
226     }
230 =item C<INTVAL is_equal(PMC *value)>
232 Returns 1 if the C<*value> is an Undef PMC, 0 otherwise.
234 =cut
238     VTABLE INTVAL is_equal(PMC *value) {
239         MMD_Undef: {
240             return 1;
241         }
242         MMD_DEFAULT: {
243             return 0;
244         }
245     }
250 =back
252 =cut
258  * Local variables:
259  *   c-file-style: "parrot"
260  * End:
261  * vim: expandtab shiftwidth=4:
262  */