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-compilation-unit ;
34 : read-quot-step ( lines -- quot/f )
35 [ parse-lines-interactive ] [
36 dup error>> unexpected-eof?
37 [ 2drop f ] [ rethrow ] if
40 : read-quot-loop ( stream accum -- quot/f )
41 over stream-readln dup [
43 dup read-quot-step dup
44 [ 2nip ] [ drop read-quot-loop ] if
49 M: object stream-read-quot
50 V{ } clone read-quot-loop ;
52 : read-quot ( -- quot/f ) input-stream get stream-read-quot ;
56 : show-var ( var -- ) visible-vars [ swap suffix ] change ;
58 : show-vars ( seq -- ) visible-vars [ swap union ] change ;
60 : hide-var ( var -- ) visible-vars [ remove ] change ;
62 : hide-vars ( seq -- ) visible-vars [ swap diff ] change ;
64 : hide-all-vars ( -- ) visible-vars off ;
68 : call-error-hook ( error -- )
69 error-continuation get error-hook get
70 call( continuation error -- ) ;
72 [ drop print-error-and-restarts ] error-hook set-global
74 SYMBOL: display-stacks?
76 t display-stacks? set-global
78 SYMBOL: max-stack-items
80 10 max-stack-items set-global
82 SYMBOL: error-summary?
84 t error-summary? set-global
88 : title. ( string -- )
89 H{ { foreground T{ rgba f 0.3 0.3 0.3 1 } } } format nl ;
91 : visible-vars. ( -- )
93 nl "--- Watched variables:" title.
94 standard-table-style [
97 [ [ short. ] with-cell ]
98 [ [ get short. ] with-cell ]
105 : trimmed-stack. ( seq -- )
106 dup length max-stack-items get > [
107 max-stack-items get cut*
109 [ length number>string "(" " more items)" surround ] keep
114 : datastack. ( datastack -- )
115 display-stacks? get [
116 [ nl "--- Data stack:" title. trimmed-stack. ] unless-empty
119 :: listener-step ( datastack -- datastack' )
120 error-summary? get [ error-summary ] when
123 input-stream get prompt prompt.
127 '[ [ datastack _ with-datastack ] with-ctrl-break ]
128 [ call-error-hook datastack ]
133 [ call-error-hook datastack ]
138 : (listener) ( datastack -- )
139 listener-step (listener) ;
143 SYMBOL: interactive-vocabs
187 "tools.profiler.sampling"
197 } interactive-vocabs set-global
199 : loaded-vocab? ( vocab-spec -- ? )
201 [ find-vocab-root not ]
202 [ source-loaded?>> +done+ eq? ]
205 : use-loaded-vocabs ( vocabs -- )
208 dup loaded-vocab? [ use-vocab ] [ drop ] if
212 : with-interactive-vocabs ( quot -- )
214 "scratchpad" set-current-vocab
215 interactive-vocabs get use-loaded-vocabs
217 ] with-manifest ; inline
222 [ { } (listener) ] with-return
223 ] with-interactive-vocabs ;
225 : listener-main ( -- )
226 version-info print flush listener ;