File:  [gforth] / gforth / smartdots.fs
Revision 1.1: download - view: text, annotated - select for diffs
Fri Mar 9 12:46:46 2012 UTC (7 years, 8 months ago) by pazsan
Branches: MAIN
CVS tags: HEAD
Gerald Wodni's idea: a smart .s to print addresses and strings

\ smart .s

: addr? ( addr -- flag )
    TRY  @  IFERROR  2drop  false  ELSE  drop  true  THEN   ENDTRY ;

: string? ( addr u -- flag )
    TRY  bounds ?DO  I c@ bl < IF  -1 throw  THEN  LOOP
	IFERROR  2drop drop false  ELSE  true  THEN  ENDTRY ;

: .string. ( addr u -- )
    '"' emit type '"' emit space ;
: .addr. ( addr -- )  hex. ;

: .s ( -- ) \ tools dot-s
\G Display the number of items on the data stack, followed by a list
\G of the items (but not more than specified by @code{maxdepth-.s};
\G TOS is the right-most item.
    ." <" depth 0 .r ." > "
    depth 0 max maxdepth-.s @ min
    dup 0
    ?do
	dup i - pick  over i - pick  2dup string? IF  .string. 2
	ELSE  drop dup addr? IF  .addr. 1
	    ELSE  .s. 1  THEN
	THEN
    +loop
    drop ;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>