# New Ticket Created by  Brent Dax 
# Please include the string:  [perl #17817]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt2/Ticket/Display.html?id=17817 >


Inspiration struck me as I was working on bug fixes for Parrot_sprintf's
patch yesterday.  One of my long-term goals with Parrot_sprintf was to
use it as the engine for a Parrot bytecode-level sprintf opcode, but I
didn't think that would be possible without duplicating the code in two
different files with different versions of the same macros wrapping
accesses to the arglist.  Obviously, this is a Bad Thing, so I just let
my mind crunch on it a while.

Until today, when I realized the solution that had been staring me in
the face all along.

The answer was vtables.  A specialized vtable wrapping argument accesses
would mean one version of the formatting code, but two different
behaviors!  Excited, I set to rewriting Parrot_sprintf--*again*--to use
this idea.

Along the way, %S went the way of %P (you should now use %Ss to insert a
STRING*, but %S will still work), two new opcodes got added, and I
managed to remove several restrictions on strings that I had imposed on
myself by using C strings internally instead of Parrot ones.  The result
(I hope) is better, faster, and stronger than the original.

When misc.c reached around a thousand lines, I decided it was becoming
unmanageable, so I split misc.c into three files.  Misc.c contains the
public "wrapper" functions around the core formatter, spf_render.c
contains the formatter and some utility functions, and spf_vtable.c
contains the two vtables used to make Parrot_sprintf work.

With all this moving around of code, the patch size became completely
unmanageable--nearly 150 KB--so the attached patch is gzipped (yes,
Windows users, WinZip and WinRAR will handle it).  It should be applied
against a freshly checked-out copy of Parrot--it includes all the
semantic and ancillary modifications of yesterday's patch.

All tests pass on Windows and Cygwin.

Share and enjoy,
--Brent Dax <[EMAIL PROTECTED]>
@roles=map {"Parrot $_"} qw(embedding regexen Configure)

Wire telegraph is a kind of a very, very long cat. You pull his tail in
New York and his head is meowing in Los Angeles. And radio operates
exactly the same way. The only difference is that there is no cat.
    --Albert Einstein (explaining radio)


-- attachment  1 ------------------------------------------------------
url: http://rt.perl.org/rt2/attach/39439/32005/c5bf0d/patch.txt.gz

Attachment: patch.txt.gz
Description: patch.txt.gz

Reply via email to