[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: PATCH: provide %c and %u8c formatting in pickle printf()
From: |
Jose E. Marchesi |
Subject: |
Re: PATCH: provide %c and %u8c formatting in pickle printf() |
Date: |
Sat, 05 Oct 2019 12:37:28 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) |
> But that seems a bit overkill? An alternative, probably more natural,
> is to catch EOF around the loop, do the right thing, then re-raise:
>
> try
> THE_LOOP_INCLUDING_draw_ascii_line;
> catch if E_eof
> {
> draw_ascii_line;
> raise E_eof;
> }
>
> Thinking about this... we have this in dump:
>
> try print_data :offset offset :top top :step 16#B;
> catch if E_eof { print "\n"; }
>
> If we make `offset' and `top' globals in print_data (as opposed to
> function arguments) then we could abstract the ascii printing into a
> print_ascii_line function, and call it in that catch:
>
> try print_data :offset offset :top top :step 16#B;
> catch if E_eof { print_ascii_line; print "\n"; }
Thinking a bit more about the problem, we can solve a lot of the
issues by not goig through the loop twice, but only once: while going
through the bytes, we print them out in hex but allso append the ASCII
representation to a string, byte by byte. Once the end is reached, we
just print the string with the collected ASCII representation. This
solves several problems
o it makes the code more compact and readable; just one loop and a
final print
o No complicated EOF catching per character, just at the very end,
we print the half-collected line at the end (essentially your version
above, but not a function call, but the collected ASCII)
o it will probably also slightly easier to do the space-padding of
lines in normal cases of running out of bytes (the other class of
problems)
Yes, that's a good idea. It also avoids mapping each byte twice, which
is costly.
Does pickle support appending characters to a string ? Or maybe
address an character-array and set characters there.
Appending characters to a string:
defvar bytes = "";
bytes = bytes + 'x' as string;
Getting a character from a string:
(poke) bytes[0]
0x78UB
Alternatively you can initialize an array of a constant number of
characters, and use it as a buffer. The resulting code would be faster.
- Re: PATCH: provide %c and %u8c formatting in pickle printf(), Jose E. Marchesi, 2019/10/01
- Re: PATCH: provide %c and %u8c formatting in pickle printf(), Henner Zeller, 2019/10/03
- Re: PATCH: provide %c and %u8c formatting in pickle printf(), Jose E. Marchesi, 2019/10/03
- Re: PATCH: provide %c and %u8c formatting in pickle printf(), Jose E. Marchesi, 2019/10/03
- Re: PATCH: provide %c and %u8c formatting in pickle printf(), Henner Zeller, 2019/10/03
- Re: PATCH: provide %c and %u8c formatting in pickle printf(), Jose E. Marchesi, 2019/10/04
- Re: PATCH: provide %c and %u8c formatting in pickle printf(), Jose E. Marchesi, 2019/10/04
- Re: PATCH: provide %c and %u8c formatting in pickle printf(), Henner Zeller, 2019/10/05
- Re: PATCH: provide %c and %u8c formatting in pickle printf(),
Jose E. Marchesi <=
- Re: PATCH: provide %c and %u8c formatting in pickle printf(), Jose E. Marchesi, 2019/10/05
- Re: PATCH: provide %c and %u8c formatting in pickle printf(), Jose E. Marchesi, 2019/10/04