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 SYMBOL: handle-ctrl-break
29 : maybe-enable-ctrl-break ( -- )
30 handle-ctrl-break get-global [ enable-ctrl-break ] when ;
32 : with-ctrl-break ( quot -- )
33 maybe-enable-ctrl-break
34 ! Always call disable-ctrl-break, no matter what handle-ctrl-break
35 ! says: it might've been changed just now by the user in the Listener.
36 ! It's a no-op if it's not enabled.
37 [ disable-ctrl-break ] [ ] cleanup ; inline
39 : parse-lines-interactive ( lines -- quot/f )
40 [ [ parse-lines ] with-ctrl-break
41 ] with-compilation-unit ;
43 : read-quot-step ( lines -- quot/f )
44 [ parse-lines-interactive ] [
45 dup error>> unexpected-eof?
46 [ 2drop f ] [ rethrow ] if
49 : read-quot-loop ( stream accum -- quot/f )
50 over stream-readln dup [
52 dup read-quot-step dup
53 [ 2nip ] [ drop read-quot-loop ] if
58 M: object stream-read-quot
59 V{ } clone read-quot-loop ;
61 : read-quot ( -- quot/f ) input-stream get stream-read-quot ;
65 : show-var ( var -- ) visible-vars [ swap suffix ] change ;
67 : show-vars ( seq -- ) visible-vars [ swap union ] change ;
69 : hide-var ( var -- ) visible-vars [ remove ] change ;
71 : hide-vars ( seq -- ) visible-vars [ swap diff ] change ;
73 : hide-all-vars ( -- ) visible-vars off ;
77 : call-error-hook ( error -- )
78 error-continuation get error-hook get
79 call( continuation error -- ) ;
81 [ drop print-error-and-restarts ] error-hook set-global
83 SYMBOL: display-stacks?
85 t display-stacks? set-global
87 SYMBOL: max-stack-items
89 10 max-stack-items set-global
91 SYMBOL: error-summary?
93 t error-summary? set-global
97 : title. ( string -- )
98 H{ { foreground T{ rgba f 0.3 0.3 0.3 1 } } } format nl ;
100 : visible-vars. ( -- )
102 nl "--- Watched variables:" title.
103 standard-table-style [
106 [ [ short. ] with-cell ]
107 [ [ get short. ] with-cell ]
114 : trimmed-stack. ( seq -- )
115 dup length max-stack-items get > [
116 max-stack-items get cut*
118 [ length number>string "(" " more items)" surround ] keep
123 : datastack. ( datastack -- )
124 display-stacks? get [
125 [ nl "--- Data stack:" title. trimmed-stack. ] unless-empty
128 :: listener-step ( datastack -- datastack' )
129 error-summary? get [ error-summary ] when
132 input-stream get prompt prompt.
136 '[ [ datastack _ with-datastack ] with-ctrl-break ]
137 [ call-error-hook datastack ]
142 [ call-error-hook datastack ]
147 : (listener) ( datastack -- )
148 listener-step (listener) ;
152 SYMBOL: interactive-vocabs
196 "tools.profiler.sampling"
206 } interactive-vocabs set-global
208 : loaded-vocab? ( vocab-spec -- ? )
210 [ find-vocab-root not ]
211 [ source-loaded?>> +done+ eq? ]
214 : use-loaded-vocabs ( vocabs -- )
217 dup loaded-vocab? [ use-vocab ] [ drop ] if
221 : with-interactive-vocabs ( quot -- )
223 "scratchpad" set-current-vocab
224 interactive-vocabs get use-loaded-vocabs
226 ] with-manifest ; inline
231 [ { } (listener) ] with-return
232 ] with-interactive-vocabs ;
234 : listener-main ( -- )
235 version-info print flush listener ;