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 /* HEADERIZER HFILE: none */
24 /* HEADERIZER BEGIN: static */
25 /* HEADERIZER END: static */
27 pmclass Pointer auto_attrs {
28 ATTR void * mark_function;
35 Initializes the pointer.
42 PObj_custom_mark_SET(SELF);
49 Marks the pointer as live.
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);
67 Creates and returns a clone of the pointer.
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);
82 =item C<void set_pointer(void *)>
84 Sets the pointer value.
90 VTABLE void set_pointer(void *ptr) {
91 PARROT_POINTER(SELF)->pointer = ptr;
96 =item C<void *get_pointer()>
98 Returns the pointer value.
104 VTABLE void *get_pointer() {
105 return PARROT_POINTER(SELF)->pointer;
110 =item C<INTVAL get_integer()>
112 Returns the pointer value as an integer.
118 VTABLE INTVAL get_integer() {
119 return (INTVAL)(PARROT_POINTER(SELF)->pointer);
124 =item C<FLOATVAL get_number()>
126 Returns the pointer value as a floating-point number.
132 VTABLE FLOATVAL get_number() {
133 return (FLOATVAL)(INTVAL)(PARROT_POINTER(SELF)->pointer);
138 =item C<STRING *get_repr()>
140 Returns the pointer value as a Parrot string.
146 VTABLE STRING *get_repr() {
147 return Parrot_sprintf_c(INTERP, "Pointer = 0x%p", PARROT_POINTER(SELF)->pointer);
153 =item C<STRING *get_string()>
155 Returns the pointer value as a Parrot string.
161 VTABLE STRING *get_string() {
162 return Parrot_sprintf_c(INTERP, "%s", PARROT_POINTER(SELF)->pointer);
167 =item C<INTVAL get_bool()>
169 Returns whether the pointer is not C<NULL>.
175 VTABLE INTVAL get_bool() {
176 return (INTVAL)(PMC_data(SELF) != NULL);
181 =item C<INTVAL is_same(PMC *pmc2)>
183 Returns whether the pointer has the same value as C<*pmc2>.
189 VTABLE INTVAL is_same(PMC *pmc2) {
190 return (INTVAL)(SELF->vtable == pmc2->vtable &&
191 PARROT_POINTER(SELF)->pointer == PARROT_POINTER(pmc2)->pointer);
205 * c-file-style: "parrot"
207 * vim: expandtab shiftwidth=4: