1 ! Copyright (C) 2003, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors colors colors.constants
4 combinators.short-circuit compiler.units continuations debugger
5 fry io io.styles kernel lexer literals locals math math.parser
6 namespaces parser parser.notes prettyprint sequences sets
7 source-files.errors system vocabs vocabs.loader
11 GENERIC: stream-read-quot ( stream -- quot/f )
12 GENERIC# prompt. 1 ( stream prompt -- )
15 manifest get current-vocab>> [ name>> "IN: " prepend ] [ "" ] if*
16 auto-use? get [ " auto-use" append ] when ;
20 { background T{ rgba f 1 0.7 0.7 1 } }
21 { foreground COLOR: black }
22 } prompt-style set-global
25 nip prompt-style get-global format bl flush ;
27 : parse-lines-interactive ( lines -- quot/f )
28 [ parse-lines ] with-compilation-unit ;
30 : read-quot-step ( lines -- quot/f )
31 [ parse-lines-interactive ] [
32 dup error>> unexpected-eof?
33 [ 2drop f ] [ rethrow ] if
36 : read-quot-loop ( stream accum -- quot/f )
37 over stream-readln dup [
39 dup read-quot-step dup
40 [ 2nip ] [ drop read-quot-loop ] if
45 M: object stream-read-quot
46 V{ } clone read-quot-loop ;
48 : read-quot ( -- quot/f ) input-stream get stream-read-quot ;
52 : show-var ( var -- ) visible-vars [ swap suffix ] change ;
54 : show-vars ( seq -- ) visible-vars [ swap union ] change ;
56 : hide-var ( var -- ) visible-vars [ remove ] change ;
58 : hide-vars ( seq -- ) visible-vars [ swap diff ] change ;
60 : hide-all-vars ( -- ) visible-vars off ;
64 : call-error-hook ( error -- )
65 error-continuation get error-hook get
66 call( continuation error -- ) ;
68 [ drop print-error-and-restarts ] error-hook set-global
70 SYMBOL: display-stacks?
72 t display-stacks? set-global
74 SYMBOL: max-stack-items
76 10 max-stack-items set-global
78 SYMBOL: error-summary?
80 t error-summary? set-global
84 : title. ( string -- )
85 H{ { foreground T{ rgba f 0.3 0.3 0.3 1 } } } format nl ;
87 : visible-vars. ( -- )
89 nl "--- Watched variables:" title.
90 standard-table-style [
93 [ [ short. ] with-cell ]
94 [ [ get short. ] with-cell ]
101 : trimmed-stack. ( seq -- )
102 dup length max-stack-items get > [
103 max-stack-items get cut*
105 [ length number>string "(" " more items)" surround ] keep
110 : datastack. ( datastack -- )
111 display-stacks? get [
112 [ nl "--- Data stack:" title. trimmed-stack. ] unless-empty
115 :: listener-step ( datastack -- datastack' )
116 error-summary? get [ error-summary ] when
119 input-stream get prompt prompt.
123 '[ datastack _ with-datastack ]
124 [ call-error-hook datastack ]
129 [ call-error-hook datastack ]
134 : (listener) ( datastack -- )
135 listener-step (listener) ;
139 SYMBOL: interactive-vocabs
183 "tools.profiler.sampling"
193 } interactive-vocabs set-global
195 : loaded-vocab? ( vocab-spec -- ? )
197 [ find-vocab-root not ]
198 [ source-loaded?>> +done+ eq? ]
201 : use-loaded-vocabs ( vocabs -- )
204 dup loaded-vocab? [ use-vocab ] [ drop ] if
208 : with-interactive-vocabs ( quot -- )
210 "scratchpad" set-current-vocab
211 interactive-vocabs get use-loaded-vocabs
213 ] with-manifest ; inline
218 [ { } (listener) ] with-return
219 ] with-interactive-vocabs ;
221 : listener-main ( -- )
222 version-info print flush listener ;