Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: chromatic/earl…
Fetching contributors…

Cannot retrieve contributors at this time

216 lines (132 sloc) 3.174 kb
/*
Copyright (C) 2001-2011, Parrot Foundation.
=head1 NAME
src/pmc/pointer.pmc - Pointer
=head1 DESCRIPTION
These are the vtable functions for the Pointer base class.
The actual pointer is in C<PMC_data>.
=head2 Methods
=over 4
=cut
*/
/* HEADERIZER HFILE: none */
/* HEADERIZER BEGIN: static */
/* HEADERIZER END: static */
pmclass Pointer auto_attrs {
ATTR void * mark_function;
ATTR void * pointer;
/*
=item C<void init()>
Initializes the pointer.
=cut
*/
VTABLE void init() {
UNUSED(interp);
PObj_custom_mark_SET(SELF);
}
/*
=item C<void mark()>
Marks the pointer as live.
=cut
*/
VTABLE void mark() {
void (*mark_function)(Interp *, void *) =
(void (*)(Interp *, void *))D2FPTR(PARROT_POINTER(SELF)->mark_function);
void * const data = PARROT_POINTER(SELF)->pointer;
if (data && mark_function)
(*mark_function)(INTERP, data);
}
/*
=item C<PMC *clone()>
Creates and returns a clone of the pointer.
=cut
*/
VTABLE PMC *clone() {
PMC * const dest = Parrot_pmc_new_noinit(INTERP, SELF->vtable->base_type);
PObj_custom_mark_SET(dest);
PMC_data(dest) = PMC_data(SELF);
return dest;
}
/*
=item C<void set_pointer(void *)>
Sets the pointer value.
=cut
*/
VTABLE void set_pointer(void *ptr) {
UNUSED(interp);
PARROT_POINTER(SELF)->pointer = ptr;
}
/*
=item C<void *get_pointer()>
Returns the pointer value.
=cut
*/
VTABLE void *get_pointer() {
UNUSED(interp);
return PARROT_POINTER(SELF)->pointer;
}
/*
=item C<INTVAL get_integer()>
Returns the pointer value as an integer.
=cut
*/
VTABLE INTVAL get_integer() {
UNUSED(interp);
return (INTVAL)(PARROT_POINTER(SELF)->pointer);
}
/*
=item C<FLOATVAL get_number()>
Returns the pointer value as a floating-point number.
=cut
*/
VTABLE FLOATVAL get_number() {
UNUSED(interp);
return (FLOATVAL)(INTVAL)(PARROT_POINTER(SELF)->pointer);
}
/*
=item C<STRING *get_repr()>
Returns the pointer value as a Parrot string.
=cut
*/
VTABLE STRING *get_repr() {
UNUSED(interp);
return Parrot_sprintf_c(INTERP, "Pointer = 0x%p", PARROT_POINTER(SELF)->pointer);
}
/*
=item C<STRING *get_string()>
Returns the pointer value as a Parrot string.
=cut
*/
VTABLE STRING *get_string() {
return Parrot_sprintf_c(INTERP, "%s", PARROT_POINTER(SELF)->pointer);
}
/*
=item C<INTVAL get_bool()>
Returns whether the pointer is not C<NULL>.
=cut
*/
VTABLE INTVAL get_bool() {
UNUSED(interp);
return (INTVAL)(PMC_data(SELF) != NULL);
}
/*
=item C<INTVAL is_same(PMC *pmc2)>
Returns whether the pointer has the same value as C<*pmc2>.
=cut
*/
VTABLE INTVAL is_same(PMC *pmc2) {
UNUSED(interp);
return (INTVAL)(SELF->vtable == pmc2->vtable &&
PARROT_POINTER(SELF)->pointer == PARROT_POINTER(pmc2)->pointer);
}
}
/*
=back
=cut
*/
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4 cinoptions='\:2=2' :
*/
Jump to Line
Something went wrong with that request. Please try again.