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 locals math math.parser namespaces
6 parser parser.notes prettyprint sequences sets
7 source-files.errors system vocabs vocabs.loader vocabs.parser ;
10 GENERIC: stream-read-quot ( stream -- quot/f )
11 GENERIC# prompt. 1 ( stream prompt -- )
14 manifest get current-vocab>> [ name>> "IN: " prepend ] [ "" ] if*
15 auto-use? get [ " auto-use" append ] when ;
19 { background T{ rgba f 1 0.7 0.7 1 } }
20 { foreground COLOR: black }
23 : parse-lines-interactive ( lines -- quot/f )
24 [ parse-lines ] with-compilation-unit ;
26 : read-quot-step ( lines -- quot/f )
27 [ parse-lines-interactive ] [
28 dup error>> unexpected-eof?
29 [ 2drop f ] [ rethrow ] if
32 : read-quot-loop ( stream accum -- quot/f )
33 over stream-readln dup [
35 dup read-quot-step dup
36 [ 2nip ] [ drop read-quot-loop ] if
41 M: object stream-read-quot
42 V{ } clone read-quot-loop ;
44 : read-quot ( -- quot/f ) input-stream get stream-read-quot ;
48 : show-var ( var -- ) visible-vars [ swap suffix ] change ;
50 : show-vars ( seq -- ) visible-vars [ swap union ] change ;
52 : hide-var ( var -- ) visible-vars [ remove ] change ;
54 : hide-vars ( seq -- ) visible-vars [ swap diff ] change ;
56 : hide-all-vars ( -- ) visible-vars off ;
60 : call-error-hook ( error -- )
61 error-continuation get error-hook get
62 call( continuation error -- ) ;
64 [ drop print-error-and-restarts ] error-hook set-global
66 SYMBOL: display-stacks?
68 t display-stacks? set-global
70 SYMBOL: max-stack-items
72 10 max-stack-items set-global
74 SYMBOL: error-summary?
76 t error-summary? set-global
80 : title. ( string -- )
81 H{ { foreground T{ rgba f 0.3 0.3 0.3 1 } } } format nl ;
83 : visible-vars. ( -- )
85 nl "--- Watched variables:" title.
86 standard-table-style [
89 [ [ short. ] with-cell ]
90 [ [ get short. ] with-cell ]
97 : trimmed-stack. ( seq -- )
98 dup length max-stack-items get > [
99 max-stack-items get cut*
101 [ length number>string "(" " more items)" surround ] keep
106 : datastack. ( datastack -- )
107 display-stacks? get [
108 [ nl "--- Data stack:" title. trimmed-stack. ] unless-empty
111 :: listener-step ( datastack -- datastack' )
112 error-summary? get [ error-summary ] when
115 input-stream get prompt prompt.
119 '[ datastack _ with-datastack ]
120 [ call-error-hook datastack ]
125 [ call-error-hook datastack ]
130 : (listener) ( datastack -- )
131 listener-step (listener) ;
135 SYMBOL: interactive-vocabs
179 "tools.profiler.sampling"
189 } interactive-vocabs set-global
191 : loaded-vocab? ( vocab-spec -- ? )
193 [ find-vocab-root not ]
194 [ source-loaded?>> +done+ eq? ]
197 : use-loaded-vocabs ( vocabs -- )
200 dup loaded-vocab? [ use-vocab ] [ drop ] if
204 : with-interactive-vocabs ( quot -- )
206 "scratchpad" set-current-vocab
207 interactive-vocabs get use-loaded-vocabs
209 ] with-manifest ; inline
214 [ { } (listener) ] with-return
215 ] with-interactive-vocabs ;
217 : listener-main ( -- )
218 version-info print flush listener ;