NAME ^

src/spf_vtable.c - Parrot sprintf

DESCRIPTION ^

Implements the two families of functions Parrot_sprintf may use to retrieve arguments.

Var args Functions ^

static STRING *getchr_va

Gets a char out of the va_list in obj and returns it as a Parrot STRING.

size is unused.

static HUGEINTVAL getint_va

Gets an integer out of the va_list in obj and returns it as a Parrot STRING.

size is an enum spf_type_t value which indicates the storage type of the integer.

static UHUGEINTVAL getuint_va

Gets an unsigned integer out of the va_list in obj and returns it as a Parrot STRING.

size is an enum spf_type_t value which indicates the storage type of the integer.

static HUGEFLOATVAL getfloat_va

Gets an floating-point number out of the va_list in obj and returns it as a Parrot STRING.

size is an enum spf_type_t value which indicates the storage type of the number.

static STRING *getstring_va

Gets an string out of the va_list in obj and returns it as a Parrot STRING.

size is an enum spf_type_t value which indicates the storage type of the string.

static void *getptr_va

Gets a void * out of the va_list in obj and returns it.

size is unused.

PMC Functions ^

static STRING *getchr_pmc

Same as getchr_va() except that a vtable is used to get the value from obj.

static HUGEINTVAL getint_pmc

Same as getint_va() except that a vtable is used to get the value from obj.

static UHUGEINTVAL getuint_pmc

Same as getuint_va() except that a vtable is used to get the value from obj.

static HUGEFLOATVAL getfloat_pmc

Same as getfloat_va() except that a vtable is used to get the value from obj.

static STRING *getstring_pmc

Same as getstring_va() except that a vtable is used to get the value from obj.

static void *getptr_pmc

Same as getptr_va() except that a vtable is used to get the value from obj.

SEE ALSO ^

src/misc.h, src/misc.c, src/spf_render.c.

HISTORY ^

When I was first working on this implementation of sprintf, I ran into a problem. I wanted to re-use the implementation for a Parrot bytecode-level sprintf, but that couldn't be done, since it used va_* directly. For a while I thought about generating two versions of the source with a Perl script, but that seemed like overkill. Eventually I came across this idea -- pass in a specialized vtable with methods for extracting things from the arglist, whatever it happened to be. This is the result.

TODO ^

In the future, it may be deemed desirable to similarly vtable-ize appending things to the string, allowing for faster PIO_printf() &c, as well as a version that writes directly to a C string. However, at this point neither of those is needed.


parrot