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 need_ext {
24 ATTR void * mark_function;
31 Initializes the pointer.
38 PObj_custom_mark_destroy_SETALL(SELF);
39 PMC_data(SELF) = mem_allocate_zeroed_typed(Parrot_Pointer_attributes);
44 =item C<void destroy()>
46 Destroy the Pointer and free associated memory
52 VTABLE void destroy() {
53 mem_sys_free(PARROT_POINTER(SELF));
54 PMC_data(SELF) = NULL;
62 Marks the pointer as live.
69 void (*mark_function)(Interp *, void *) =
70 (void (*)(Interp *, void *))D2FPTR(PARROT_POINTER(SELF)->mark_function);
71 void * data = PARROT_POINTER(SELF)->pointer;
72 if (data && mark_function)
73 (*mark_function)(INTERP, data);
80 Creates and returns a clone of the pointer.
87 PMC * const dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
88 PObj_custom_mark_SET(dest);
89 PMC_data(dest) = PMC_data(SELF);
95 =item C<void set_pointer(void *)>
97 Sets the pointer value.
103 VTABLE void set_pointer(void *ptr) {
104 PARROT_POINTER(SELF)->pointer = ptr;
109 =item C<void *get_pointer()>
111 Returns the pointer value.
117 VTABLE void *get_pointer() {
118 return PARROT_POINTER(SELF)->pointer;
123 =item C<INTVAL get_integer()>
125 Returns the pointer value as an integer.
131 VTABLE INTVAL get_integer() {
132 return (INTVAL)(PARROT_POINTER(SELF)->pointer);
137 =item C<FLOATVAL get_number()>
139 Returns the pointer value as a floating-point number.
145 VTABLE FLOATVAL get_number() {
146 return (FLOATVAL)(INTVAL)(PARROT_POINTER(SELF)->pointer);
151 =item C<STRING *get_repr()>
153 Returns the pointer value as a Parrot string.
159 VTABLE STRING *get_repr() {
160 return Parrot_sprintf_c(INTERP, "Pointer = 0x%p", PARROT_POINTER(SELF)->pointer);
166 =item C<STRING *get_string()>
168 Returns the pointer value as a Parrot string.
174 VTABLE STRING *get_string() {
175 return Parrot_sprintf_c(INTERP, "%s", PARROT_POINTER(SELF)->pointer);
180 =item C<INTVAL get_bool()>
182 Returns whether the pointer is not C<NULL>.
188 VTABLE INTVAL get_bool() {
189 return (INTVAL)(PMC_data(SELF) != NULL);
194 =item C<INTVAL is_same(PMC *pmc2)>
196 Returns whether the pointer has the same value as C<*pmc2>.
202 VTABLE INTVAL is_same(PMC *pmc2) {
203 return (INTVAL)(SELF->vtable == pmc2->vtable &&
204 PARROT_POINTER(SELF)->pointer == PARROT_POINTER(pmc2)->pointer);
218 * c-file-style: "parrot"
220 * vim: expandtab shiftwidth=4: