2 Copyright (C) 2001-2007, Parrot Foundation.
7 src/pmc/pointer.pmc - Pointer
11 These are the vtable functions for the Pointer base class.
13 The actual pointer is in C<PMC_data>.
23 pmclass Pointer auto_attrs {
24 ATTR void * mark_function;
31 Initializes the pointer.
38 PObj_custom_mark_SET(SELF);
45 Marks the pointer as live.
52 void (*mark_function)(Interp *, void *) =
53 (void (*)(Interp *, void *))D2FPTR(PARROT_POINTER(SELF)->mark_function);
54 void * data = PARROT_POINTER(SELF)->pointer;
55 if (data && mark_function)
56 (*mark_function)(INTERP, data);
63 Creates and returns a clone of the pointer.
70 PMC * const dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
71 PObj_custom_mark_SET(dest);
72 PMC_data(dest) = PMC_data(SELF);
78 =item C<void set_pointer(void *)>
80 Sets the pointer value.
86 VTABLE void set_pointer(void *ptr) {
87 PARROT_POINTER(SELF)->pointer = ptr;
92 =item C<void *get_pointer()>
94 Returns the pointer value.
100 VTABLE void *get_pointer() {
101 return PARROT_POINTER(SELF)->pointer;
106 =item C<INTVAL get_integer()>
108 Returns the pointer value as an integer.
114 VTABLE INTVAL get_integer() {
115 return (INTVAL)(PARROT_POINTER(SELF)->pointer);
120 =item C<FLOATVAL get_number()>
122 Returns the pointer value as a floating-point number.
128 VTABLE FLOATVAL get_number() {
129 return (FLOATVAL)(INTVAL)(PARROT_POINTER(SELF)->pointer);
134 =item C<STRING *get_repr()>
136 Returns the pointer value as a Parrot string.
142 VTABLE STRING *get_repr() {
143 return Parrot_sprintf_c(INTERP, "Pointer = 0x%p", PARROT_POINTER(SELF)->pointer);
149 =item C<STRING *get_string()>
151 Returns the pointer value as a Parrot string.
157 VTABLE STRING *get_string() {
158 return Parrot_sprintf_c(INTERP, "%s", PARROT_POINTER(SELF)->pointer);
163 =item C<INTVAL get_bool()>
165 Returns whether the pointer is not C<NULL>.
171 VTABLE INTVAL get_bool() {
172 return (INTVAL)(PMC_data(SELF) != NULL);
177 =item C<INTVAL is_same(PMC *pmc2)>
179 Returns whether the pointer has the same value as C<*pmc2>.
185 VTABLE INTVAL is_same(PMC *pmc2) {
186 return (INTVAL)(SELF->vtable == pmc2->vtable &&
187 PARROT_POINTER(SELF)->pointer == PARROT_POINTER(pmc2)->pointer);
201 * c-file-style: "parrot"
203 * vim: expandtab shiftwidth=4: