1 ! Copyright (C) 2003, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays accessors assocs colors combinators grouping io
4 io.streams.string io.styles kernel make math math.parser namespaces
5 parser prettyprint.backend prettyprint.config prettyprint.custom
6 prettyprint.sections quotations sequences sorting strings vocabs
7 vocabs.prettyprint words sets generic ;
8 FROM: namespaces => set ;
11 : with-use ( obj quot -- )
12 make-pprint (pprint-manifest
13 [ pprint-manifest) ] [ [ drop nl ] unless-empty ] bi
16 : with-in ( obj quot -- )
17 make-pprint current-vocab>> [ pprint-in bl ] when* do-pprint ; inline
19 : pprint ( obj -- ) [ pprint* ] with-pprint ;
21 : . ( obj -- ) pprint nl ;
23 : pprint-use ( obj -- ) [ pprint* ] with-use ;
25 : unparse ( obj -- str ) [ pprint ] with-string-writer ;
27 : unparse-use ( obj -- str ) [ pprint-use ] with-string-writer ;
29 : pprint-short ( obj -- )
30 [ pprint ] with-short-limits ;
32 : unparse-short ( obj -- str )
33 [ pprint-short ] with-string-writer ;
35 : short. ( obj -- ) pprint-short nl ;
37 : .b ( n -- ) >bin print ;
38 : .o ( n -- ) >oct print ;
39 : .h ( n -- ) >hex print ;
41 : stack. ( seq -- ) [ short. ] each ;
43 : .s ( -- ) datastack stack. ;
44 : .r ( -- ) retainstack stack. ;
51 { { foreground T{ rgba f 1 1 1 1 } } { background T{ rgba f 0 0 0 1 } } }
52 "word-style" set-word-prop
54 : remove-step-into ( word -- )
55 building get [ nip pop wrapped>> ] unless-empty , ;
57 : (remove-breakpoints) ( quot -- newquot )
61 { [ dup word? not ] [ , ] }
62 { [ dup "break?" word-prop ] [ drop ] }
63 { [ dup "step-into?" word-prop ] [ remove-step-into ] }
69 : remove-breakpoints ( quot pos -- quot' )
70 1 + short cut [ (remove-breakpoints) ] bi@ [ -> ] glue ;
72 : optimized-frame? ( triple -- ? ) second word? ;
74 : frame-word? ( triple -- ? )
77 : frame-word. ( triple -- )
79 { [ dup method? ] [ "Method: " write pprint ] }
80 { [ dup word? ] [ "Word: " write pprint ] }
84 : optimized-frame. ( triple -- )
86 [ "(O)" write ] with-cell
87 [ frame-word. ] with-cell
90 : unoptimized-frame. ( triple -- )
92 [ "(U)" write ] with-cell
95 dup [ second ] [ third ] bi remove-breakpoints
106 [ frame-word. ] with-cell
110 : callframe. ( triple -- )
112 [ optimized-frame. ] [ unoptimized-frame. ] if ;
116 : callstack. ( callstack -- )
117 callstack>array 3 <groups>
118 { { table-gap { 5 5 } } } [ [ callframe. ] each ] tabular-output nl ;
120 : .c ( -- ) callstack callstack. ;
122 : pprint-cell ( obj -- ) [ pprint-short ] with-cell ;
124 SYMBOL: pprint-string-cells?
126 : simple-table. ( values -- )
127 standard-table-style [
131 dup string? pprint-string-cells? get not and
132 [ [ write ] with-cell ]
138 ] tabular-output nl ;
140 : object-table. ( obj alist -- )
141 [ [ nip first ] [ second call( obj -- str ) ] 2bi 2array ] with map