2010-02-01 00:45:08 -05:00
|
|
|
! Copyright (C) 2003, 2010 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2015-08-04 23:37:29 -04:00
|
|
|
USING: accessors arrays classes colors.constants combinators
|
|
|
|
continuations generic grouping io io.streams.string io.styles
|
|
|
|
kernel make math math.parser namespaces prettyprint.config
|
|
|
|
prettyprint.custom prettyprint.sections sequences strings
|
|
|
|
vocabs.prettyprint words ;
|
2008-08-01 18:32:30 -04:00
|
|
|
IN: prettyprint
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: with-use ( obj quot -- )
|
2013-04-06 15:45:15 -04:00
|
|
|
t make-pprint (pprint-manifest
|
2009-05-16 09:54:14 -04:00
|
|
|
[ pprint-manifest) ] [ [ drop nl ] unless-empty ] bi
|
2009-03-13 03:58:09 -04:00
|
|
|
do-pprint ; inline
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: with-in ( obj quot -- )
|
2013-04-06 15:45:15 -04:00
|
|
|
t make-pprint current-vocab>> [ pprint-in bl ] when* do-pprint ; inline
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: pprint ( obj -- ) [ pprint* ] with-pprint ;
|
|
|
|
|
2008-08-12 04:31:48 -04:00
|
|
|
: . ( obj -- ) pprint nl ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2014-10-09 21:50:38 -04:00
|
|
|
: ... ( obj -- ) [ . ] without-limits ;
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: pprint-use ( obj -- ) [ pprint* ] with-use ;
|
|
|
|
|
2008-02-15 23:20:31 -05:00
|
|
|
: unparse ( obj -- str ) [ pprint ] with-string-writer ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-02-15 23:20:31 -05:00
|
|
|
: unparse-use ( obj -- str ) [ pprint-use ] with-string-writer ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
|
|
|
: pprint-short ( obj -- )
|
2010-02-19 18:18:16 -05:00
|
|
|
[ pprint ] with-short-limits ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-02-21 02:26:44 -05:00
|
|
|
: unparse-short ( obj -- str )
|
|
|
|
[ pprint-short ] with-string-writer ;
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: short. ( obj -- ) pprint-short nl ;
|
|
|
|
|
2013-04-10 22:18:15 -04:00
|
|
|
: error-in-pprint ( obj -- str )
|
2013-04-10 21:50:11 -04:00
|
|
|
class-of name>> "~pprint error: " "~" surround ;
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
: .b ( n -- ) >bin print ;
|
|
|
|
: .o ( n -- ) >oct print ;
|
|
|
|
: .h ( n -- ) >hex print ;
|
|
|
|
|
2012-06-01 20:54:58 -04:00
|
|
|
: stack. ( seq -- )
|
|
|
|
[
|
|
|
|
[ short. ] [
|
2013-04-10 22:18:15 -04:00
|
|
|
drop [ error-in-pprint ] keep write-object nl
|
2012-06-01 20:54:58 -04:00
|
|
|
] recover
|
|
|
|
] each ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-08-13 13:11:59 -04:00
|
|
|
: .s ( -- ) get-datastack stack. ;
|
|
|
|
: .r ( -- ) get-retainstack stack. ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-01-24 18:20:07 -05:00
|
|
|
<PRIVATE
|
|
|
|
|
2007-10-05 01:08:34 -04:00
|
|
|
SYMBOL: ->
|
|
|
|
|
|
|
|
\ ->
|
2015-08-04 23:37:29 -04:00
|
|
|
{ { foreground COLOR: white } { background COLOR: black } }
|
2007-10-05 01:08:34 -04:00
|
|
|
"word-style" set-word-prop
|
|
|
|
|
2008-02-21 00:13:31 -05:00
|
|
|
: remove-step-into ( word -- )
|
2008-09-06 20:13:59 -04:00
|
|
|
building get [ nip pop wrapped>> ] unless-empty , ;
|
2008-02-21 00:13:31 -05:00
|
|
|
|
|
|
|
: (remove-breakpoints) ( quot -- newquot )
|
|
|
|
[
|
|
|
|
[
|
|
|
|
{
|
|
|
|
{ [ dup word? not ] [ , ] }
|
|
|
|
{ [ dup "break?" word-prop ] [ drop ] }
|
|
|
|
{ [ dup "step-into?" word-prop ] [ remove-step-into ] }
|
2008-04-11 13:53:22 -04:00
|
|
|
[ , ]
|
2008-02-21 00:13:31 -05:00
|
|
|
} cond
|
|
|
|
] each
|
|
|
|
] [ ] make ;
|
|
|
|
|
|
|
|
: remove-breakpoints ( quot pos -- quot' )
|
2010-02-01 00:45:08 -05:00
|
|
|
1 + short cut [ (remove-breakpoints) ] bi@ [ -> ] glue ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2010-02-01 06:39:32 -05:00
|
|
|
: optimized-frame? ( triple -- ? ) second word? ;
|
|
|
|
|
|
|
|
: frame-word? ( triple -- ? )
|
|
|
|
first word? ;
|
|
|
|
|
|
|
|
: frame-word. ( triple -- )
|
|
|
|
first {
|
|
|
|
{ [ dup method? ] [ "Method: " write pprint ] }
|
|
|
|
{ [ dup word? ] [ "Word: " write pprint ] }
|
|
|
|
[ drop ]
|
|
|
|
} cond ;
|
|
|
|
|
|
|
|
: optimized-frame. ( triple -- )
|
|
|
|
[
|
|
|
|
[ "(O)" write ] with-cell
|
|
|
|
[ frame-word. ] with-cell
|
|
|
|
] with-row ;
|
|
|
|
|
|
|
|
: unoptimized-frame. ( triple -- )
|
2010-02-01 00:45:08 -05:00
|
|
|
[
|
2010-02-01 06:39:32 -05:00
|
|
|
[ "(U)" write ] with-cell
|
|
|
|
[
|
|
|
|
"Quotation: " write
|
|
|
|
dup [ second ] [ third ] bi remove-breakpoints
|
2012-07-19 14:24:45 -04:00
|
|
|
H{
|
|
|
|
{ nesting-limit 3 }
|
|
|
|
{ length-limit 100 }
|
|
|
|
} clone [ pprint ] with-variables
|
2010-02-01 06:39:32 -05:00
|
|
|
] with-cell
|
|
|
|
] with-row
|
|
|
|
dup frame-word? [
|
2008-09-27 14:47:31 -04:00
|
|
|
[
|
2010-02-01 06:39:32 -05:00
|
|
|
[ ] with-cell
|
|
|
|
[ frame-word. ] with-cell
|
|
|
|
] with-row
|
|
|
|
] [ drop ] if ;
|
|
|
|
|
|
|
|
: callframe. ( triple -- )
|
|
|
|
dup optimized-frame?
|
|
|
|
[ optimized-frame. ] [ unoptimized-frame. ] if ;
|
2010-02-01 00:45:08 -05:00
|
|
|
|
|
|
|
PRIVATE>
|
|
|
|
|
|
|
|
: callstack. ( callstack -- )
|
2010-02-01 06:39:32 -05:00
|
|
|
callstack>array 3 <groups>
|
|
|
|
{ { table-gap { 5 5 } } } [ [ callframe. ] each ] tabular-output nl ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2015-08-13 13:11:59 -04:00
|
|
|
: .c ( -- ) get-callstack callstack. ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-01-08 18:02:54 -05:00
|
|
|
: pprint-cell ( obj -- ) [ pprint-short ] with-cell ;
|
|
|
|
|
|
|
|
SYMBOL: pprint-string-cells?
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2008-11-04 18:23:08 -05:00
|
|
|
: simple-table. ( values -- )
|
|
|
|
standard-table-style [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
[
|
2009-01-08 18:02:54 -05:00
|
|
|
dup string? pprint-string-cells? get not and
|
2008-11-04 18:23:08 -05:00
|
|
|
[ [ write ] with-cell ]
|
|
|
|
[ pprint-cell ]
|
|
|
|
if
|
|
|
|
] each
|
|
|
|
] with-row
|
|
|
|
] each
|
2009-08-13 20:21:44 -04:00
|
|
|
] tabular-output nl ;
|
2009-11-05 02:07:59 -05:00
|
|
|
|
|
|
|
: object-table. ( obj alist -- )
|
|
|
|
[ [ nip first ] [ second call( obj -- str ) ] 2bi 2array ] with map
|
|
|
|
simple-table. ;
|