NAME ^

src/spf_vtable.c - Parrot sprintf

DESCRIPTION ^

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

Var args Functions ^

PARROT_CANNOT_RETURN_NULL PARROT_WARN_UNUSED_RESULT static STRING *getchr_va(PARROT_INTERP, INTVAL size, NOTNULL(SPRINTF_OBJ *obj))

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

size is unused.

PARROT_WARN_UNUSED_RESULT static HUGEINTVAL getint_va(PARROT_INTERP, INTVAL size, NOTNULL(SPRINTF_OBJ *obj))

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.

PARROT_WARN_UNUSED_RESULT static UHUGEINTVAL getuint_va(PARROT_INTERP, INTVAL size, NOTNULL(SPRINTF_OBJ *obj))

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.

PARROT_WARN_UNUSED_RESULT static HUGEFLOATVAL getfloat_va(PARROT_INTERP, INTVAL size, NOTNULL(SPRINTF_OBJ *obj))

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.

PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL static STRING *getstring_va(PARROT_INTERP, INTVAL size, NOTNULL(SPRINTF_OBJ *obj))

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.

PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL static void *getptr_va(PARROT_INTERP, SHIM(INTVAL size), NOTNULL(SPRINTF_OBJ *obj))

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

size is unused.

PMC Functions ^

PARROT_CANNOT_RETURN_NULL PARROT_WARN_UNUSED_RESULT static STRING *getchr_pmc(PARROT_INTERP, INTVAL size, NOTNULL(SPRINTF_OBJ *obj))

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

PARROT_WARN_UNUSED_RESULT static HUGEINTVAL getint_pmc(PARROT_INTERP, INTVAL size, NOTNULL(SPRINTF_OBJ *obj))

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

PARROT_WARN_UNUSED_RESULT static UHUGEINTVAL getuint_pmc(PARROT_INTERP, INTVAL size, NOTNULL(SPRINTF_OBJ *obj))

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

PARROT_WARN_UNUSED_RESULT static HUGEFLOATVAL getfloat_pmc(PARROT_INTERP, INTVAL size, NOTNULL(SPRINTF_OBJ *obj))

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

PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL static STRING *getstring_pmc(PARROT_INTERP, INTVAL size, NOTNULL(SPRINTF_OBJ *obj))

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

PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL static void *getptr_pmc(PARROT_INTERP, INTVAL size, NOTNULL(SPRINTF_OBJ *obj))

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