fix codetest failure - ASSERT_ARGS does not have a ; after and
[parrot.git] / src / pmc / pointer.pmc
blob9e5598e4201cbf3fb808f8553331cf810fb157de
1 /*
2 Copyright (C) 2001-2007, Parrot Foundation.
3 $Id$
5 =head1 NAME
7 src/pmc/pointer.pmc - Pointer
9 =head1 DESCRIPTION
11 These are the vtable functions for the Pointer base class.
13 The actual pointer is in C<PMC_data>.
15 =head2 Methods
17 =over 4
19 =cut
23 /* HEADERIZER HFILE: none */
24 /* HEADERIZER BEGIN: static */
25 /* HEADERIZER END: static */
27 pmclass Pointer auto_attrs {
28     ATTR void * mark_function;
29     ATTR void * pointer;
33 =item C<void init()>
35 Initializes the pointer.
37 =cut
41     VTABLE void init() {
42         PObj_custom_mark_SET(SELF);
43     }
47 =item C<void mark()>
49 Marks the pointer as live.
51 =cut
55     VTABLE void mark() {
56         void (*mark_function)(Interp *, void *) =
57             (void (*)(Interp *, void *))D2FPTR(PARROT_POINTER(SELF)->mark_function);
58         void * data = PARROT_POINTER(SELF)->pointer;
59         if (data && mark_function)
60             (*mark_function)(INTERP, data);
61     }
65 =item C<PMC *clone()>
67 Creates and returns a clone of the pointer.
69 =cut
73     VTABLE PMC *clone() {
74         PMC * const dest = Parrot_pmc_new_noinit(INTERP, SELF->vtable->base_type);
75         PObj_custom_mark_SET(dest);
76         PMC_data(dest) = PMC_data(SELF);
77         return dest;
78     }
82 =item C<void set_pointer(void *)>
84 Sets the pointer value.
86 =cut
90     VTABLE void set_pointer(void *ptr) {
91         PARROT_POINTER(SELF)->pointer = ptr;
92     }
96 =item C<void *get_pointer()>
98 Returns the pointer value.
100 =cut
104     VTABLE void *get_pointer() {
105         return PARROT_POINTER(SELF)->pointer;
106     }
110 =item C<INTVAL get_integer()>
112 Returns the pointer value as an integer.
114 =cut
118     VTABLE INTVAL get_integer() {
119         return (INTVAL)(PARROT_POINTER(SELF)->pointer);
120     }
124 =item C<FLOATVAL get_number()>
126 Returns the pointer value as a floating-point number.
128 =cut
132     VTABLE FLOATVAL get_number() {
133         return (FLOATVAL)(INTVAL)(PARROT_POINTER(SELF)->pointer);
134     }
138 =item C<STRING *get_repr()>
140 Returns the pointer value as a Parrot string.
142 =cut
146     VTABLE STRING *get_repr() {
147         return Parrot_sprintf_c(INTERP, "Pointer = 0x%p", PARROT_POINTER(SELF)->pointer);
148     }
153 =item C<STRING *get_string()>
155 Returns the pointer value as a Parrot string.
157 =cut
161     VTABLE STRING *get_string() {
162         return Parrot_sprintf_c(INTERP, "%s", PARROT_POINTER(SELF)->pointer);
163     }
167 =item C<INTVAL get_bool()>
169 Returns whether the pointer is not C<NULL>.
171 =cut
175     VTABLE INTVAL get_bool() {
176         return (INTVAL)(PMC_data(SELF) != NULL);
177     }
181 =item C<INTVAL is_same(PMC *pmc2)>
183 Returns whether the pointer has the same value as C<*pmc2>.
185 =cut
189     VTABLE INTVAL is_same(PMC *pmc2) {
190         return (INTVAL)(SELF->vtable   == pmc2->vtable &&
191                         PARROT_POINTER(SELF)->pointer == PARROT_POINTER(pmc2)->pointer);
192     }
197 =back
199 =cut
204  * Local variables:
205  *   c-file-style: "parrot"
206  * End:
207  * vim: expandtab shiftwidth=4:
208  */