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 : with-ctrl-break ( quot -- )
29 [ disable-ctrl-break ] [ ] cleanup ; inline
31 : parse-lines-interactive ( lines -- quot/f )
32 [ [ parse-lines ] with-ctrl-break
33 ] with-compilation-unit ;
35 : read-quot-step ( lines -- quot/f )
36 [ parse-lines-interactive ] [
37 dup error>> unexpected-eof?
38 [ 2drop f ] [ rethrow ] if
41 : read-quot-loop ( stream accum -- quot/f )
42 over stream-readln dup [
44 dup read-quot-step dup
45 [ 2nip ] [ drop read-quot-loop ] if
50 M: object stream-read-quot
51 V{ } clone read-quot-loop ;
53 : read-quot ( -- quot/f ) input-stream get stream-read-quot ;
57 : show-var ( var -- ) visible-vars [ swap suffix ] change ;
59 : show-vars ( seq -- ) visible-vars [ swap union ] change ;
61 : hide-var ( var -- ) visible-vars [ remove ] change ;
63 : hide-vars ( seq -- ) visible-vars [ swap diff ] change ;
65 : hide-all-vars ( -- ) visible-vars off ;
69 : call-error-hook ( error -- )
70 error-continuation get error-hook get
71 call( continuation error -- ) ;
73 [ drop print-error-and-restarts ] error-hook set-global
75 SYMBOL: display-stacks?
77 t display-stacks? set-global
79 SYMBOL: max-stack-items
81 10 max-stack-items set-global
83 SYMBOL: error-summary?
85 t error-summary? set-global
89 : title. ( string -- )
90 H{ { foreground T{ rgba f 0.3 0.3 0.3 1 } } } format nl ;
92 : visible-vars. ( -- )
94 nl "--- Watched variables:" title.
95 standard-table-style [
98 [ [ short. ] with-cell ]
99 [ [ get short. ] with-cell ]
106 : trimmed-stack. ( seq -- )
107 dup length max-stack-items get > [
108 max-stack-items get cut*
110 [ length number>string "(" " more items)" surround ] keep
115 : datastack. ( datastack -- )
116 display-stacks? get [
117 [ nl "--- Data stack:" title. trimmed-stack. ] unless-empty
120 :: listener-step ( datastack -- datastack' )
121 error-summary? get [ error-summary ] when
124 input-stream get prompt prompt.
128 '[ [ datastack _ with-datastack ] with-ctrl-break ]
129 [ call-error-hook datastack ]
134 [ call-error-hook datastack ]
139 : (listener) ( datastack -- )
140 listener-step (listener) ;
144 SYMBOL: interactive-vocabs
188 "tools.profiler.sampling"
198 } interactive-vocabs set-global
200 : loaded-vocab? ( vocab-spec -- ? )
202 [ find-vocab-root not ]
203 [ source-loaded?>> +done+ eq? ]
206 : use-loaded-vocabs ( vocabs -- )
209 dup loaded-vocab? [ use-vocab ] [ drop ] if
213 : with-interactive-vocabs ( quot -- )
215 "scratchpad" set-current-vocab
216 interactive-vocabs get use-loaded-vocabs
218 ] with-manifest ; inline
223 [ { } (listener) ] with-return
224 ] with-interactive-vocabs ;
226 : listener-main ( -- )
227 version-info print flush listener ;