parrotcode: Parrot sprintf | |
Contents | C |
src/spf_vtable.c - Parrot sprintf
Implements the two families of functions Parrot_sprintf
may use to retrieve arguments.
PARROT_CANNOT_RETURN_NULL PARROT_WARN_UNUSED_RESULT static STRING *getchr_va(PARROT_INTERP, INTVAL size, NOTNULL(SPRINTF_OBJ *obj))
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))
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))
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))
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))
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))
void *
out of the va_list
in obj
and returns it.size
is unused.PARROT_CANNOT_RETURN_NULL PARROT_WARN_UNUSED_RESULT static STRING *getchr_pmc(PARROT_INTERP, INTVAL size, NOTNULL(SPRINTF_OBJ *obj))
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))
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))
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))
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))
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))
getptr_va()
except that a vtable is used to get the value from obj
.src/misc.h, src/misc.c, src/spf_render.c.
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.
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.
|