parrotcode: Parrot sprintf | |
Contents | C |
src/spf_vtable.c - Parrot sprintf
Implements the two families of functions Parrot_sprintf
may use to retrieve arguments.
static STRING *getchr_va(Interp *interp, INTVAL size, SPRINTF_OBJ *obj)
char
out of the va_list
in obj
and returns it as a Parrot STRING
.size
is unused.static HUGEINTVAL getint_va(Interp *interp, INTVAL size, 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.static UHUGEINTVAL getuint_va(Interp *interp, INTVAL size, 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.static HUGEFLOATVAL getfloat_va(Interp *interp, INTVAL size, 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.static STRING *getstring_va(Interp *interp, INTVAL size, 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.static void *getptr_va(Interp *interp, INTVAL size, SPRINTF_OBJ *obj)
void *
out of the va_list
in obj
and returns it.size
is unused.static STRING *getchr_pmc(Interp *interp, INTVAL size, SPRINTF_OBJ *obj)
getchr_va()
except that a vtable is used to get the value from obj
.static HUGEINTVAL getint_pmc(Interp *interp, INTVAL size, SPRINTF_OBJ *obj)
getint_va()
except that a vtable is used to get the value from obj
.static UHUGEINTVAL getuint_pmc(Interp *interp, INTVAL size, SPRINTF_OBJ *obj)
getuint_va()
except that a vtable is used to get the value from obj
.static HUGEFLOATVAL getfloat_pmc(Interp *interp, INTVAL size, SPRINTF_OBJ *obj)
getfloat_va()
except that a vtable is used to get the value from obj
.static STRING *getstring_pmc(Interp *interp, INTVAL size, SPRINTF_OBJ *obj)
getstring_va()
except that a vtable is used to get the value from obj
.static void *getptr_pmc(Interp *interp, INTVAL size, 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.
|