Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tag: RELEASE_0_6_2
Fetching contributors…

Cannot retrieve contributors at this time

179 lines (106 sloc) 2.44 kB
/*
Copyright (C) 2001-2007, The Perl Foundation.
$Id$
=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
*/
#include "parrot/parrot.h"
pmclass Pointer need_ext {
/*
=item C<void init()>
Initializes the pointer.
=cut
*/
VTABLE void init() {
PObj_custom_mark_SET(SELF);
}
/*
=item C<void morph(INTVAL type)>
Does nothing.
=cut
*/
VTABLE void morph(INTVAL type) {
}
/*
=item C<void mark()>
Marks the pointer as live.
=cut
*/
VTABLE void mark() {
void (*mark_function)(Interp *, void *) =
(void (*)(Interp *, void *))D2FPTR(PMC_struct_val(SELF));
if (PMC_data(SELF) && PMC_struct_val(SELF))
(*mark_function)(INTERP, PMC_data(SELF));
}
/*
=item C<PMC *clone()>
Creates and returns a clone of the pointer.
=cut
*/
VTABLE PMC *clone() {
PMC * const dest = pmc_new_noinit(INTERP, SELF->vtable->base_type);
PObj_custom_mark_SET(dest);
PMC_data(dest) = PMC_data(SELF);
return dest;
}
/*
=item C<INTVAL get_integer()>
Returns the pointer value as an integer.
=cut
*/
VTABLE INTVAL get_integer() {
return (INTVAL)PMC_data(SELF);
}
/*
=item C<FLOATVAL get_number()>
Returns the pointer value as a floating-point number.
=cut
*/
VTABLE FLOATVAL get_number() {
return (FLOATVAL)(INTVAL)PMC_data(SELF);
}
/*
=item C<STRING *get_string()>
Returns the pointer value as a Parrot string.
=cut
*/
VTABLE STRING *get_string() {
char buffer[64];
const size_t len = snprintf(buffer, sizeof (buffer), "Pointer = 0x%p", PMC_data(SELF));
STRING * const ret = string_make(INTERP, buffer, len, "iso-8859-1", 0);
return ret;
}
/*
=item C<INTVAL get_bool()>
Returns whether the pointer is not C<NULL>.
=cut
*/
VTABLE INTVAL get_bool() {
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) {
return (INTVAL)(SELF->vtable == pmc2->vtable &&
PMC_data(SELF) == PMC_data(pmc2));
}
}
/*
=back
=cut
*/
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/
Jump to Line
Something went wrong with that request. Please try again.