Am 04.11.2010 um 23:16 schrieb Segher Boessenkool:
Maybe something like this:
: .p-reg ( prop len -- )
r >r my-#scells my-#acells dup r> r> bounds ?DO
2dup = IF cr THEN \ start of line dup 0= IF 2 spaces THEN \ start of "size" part dup 3 and 0= IF space THEN \ make numbers more readable i c@ 2 0.r \ print byte 1- 3dup nip + 0= IF drop dup THEN \ update counter LOOP ;
(untested, mind the bogons).
Leads to:
0 > dev /memory ok 0 > .properties name "memory" device_type "memory" reg 00 00 00 00 40 00 00 00 N?!H -- 5 : 4e 80 04 21 48 available 00 00 40 00 3f bd 40 00 <empty> ok
My patch did:
0 > dev /memory ok 0 > .properties name "memory" device_type "memory" reg 00000000 40000000 available 00004000 3fbd4000 ok
Any hint? My code may have been inefficient but better unstandable for a Forth newbie...
I found it quite the opposite -- I'm not a newbie but I found it very hard to read. Maybe needs a bit more factoring?
I forgot to multiply acells and scells by 4; also, no indent, and I put the newlines at the start of the line, not the end (this is normal in Forth, and has some advantages). This needs changing here of course.
Figured that out myself in the meantime, also the 3drop after some trial and error:
: .p-reg ( data len -- )
r >r my-#scells 4 * my-#acells 4 * dup r> r> ( #sbytes #abytes
#abytes data len ) bounds ( #sbytes #abytes #abytes data+len data ) ?do \ 2dup = if cr then \ start of line dup 0= if 2 spaces then \ start of "size" part 2dup <> if dup 3 and 0= if space then \ make numbers more readable then i c@ 2 0.r \ print byte 1- 3dup nip + 0= if cr 0 begin ." " 1+ dup d# 26 >= until drop drop dup \ update counter then loop 3drop ;
This also fixes a leading space.
Thanks a lot for your review and suggestions, I'll put together a patch series tomorrow.
Andreas