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 ui.gadgets.theme 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 $ prompt-background-color }
21 { foreground $ text-color }
24 : parse-lines-interactive ( lines -- quot/f )
25 [ parse-lines ] with-compilation-unit ;
27 : read-quot-step ( lines -- quot/f )
28 [ parse-lines-interactive ] [
29 dup error>> unexpected-eof?
30 [ 2drop f ] [ rethrow ] if
33 : read-quot-loop ( stream accum -- quot/f )
34 over stream-readln dup [
36 dup read-quot-step dup
37 [ 2nip ] [ drop read-quot-loop ] if
42 M: object stream-read-quot
43 V{ } clone read-quot-loop ;
45 : read-quot ( -- quot/f ) input-stream get stream-read-quot ;
49 : show-var ( var -- ) visible-vars [ swap suffix ] change ;
51 : show-vars ( seq -- ) visible-vars [ swap union ] change ;
53 : hide-var ( var -- ) visible-vars [ remove ] change ;
55 : hide-vars ( seq -- ) visible-vars [ swap diff ] change ;
57 : hide-all-vars ( -- ) visible-vars off ;
61 : call-error-hook ( error -- )
62 error-continuation get error-hook get
63 call( continuation error -- ) ;
65 [ drop print-error-and-restarts ] error-hook set-global
67 SYMBOL: display-stacks?
69 t display-stacks? set-global
71 SYMBOL: max-stack-items
73 10 max-stack-items set-global
75 SYMBOL: error-summary?
77 t error-summary? set-global
81 : title. ( string -- )
82 H{ { foreground T{ rgba f 0.3 0.3 0.3 1 } } } format nl ;
84 : visible-vars. ( -- )
86 nl "--- Watched variables:" title.
87 standard-table-style [
90 [ [ short. ] with-cell ]
91 [ [ get short. ] with-cell ]
98 : trimmed-stack. ( seq -- )
99 dup length max-stack-items get > [
100 max-stack-items get cut*
102 [ length number>string "(" " more items)" surround ] keep
107 : datastack. ( datastack -- )
108 display-stacks? get [
109 [ nl "--- Data stack:" title. trimmed-stack. ] unless-empty
112 :: listener-step ( datastack -- datastack' )
113 error-summary? get [ error-summary ] when
116 input-stream get prompt prompt.
120 '[ datastack _ with-datastack ]
121 [ call-error-hook datastack ]
126 [ call-error-hook datastack ]
131 : (listener) ( datastack -- )
132 listener-step (listener) ;
136 SYMBOL: interactive-vocabs
180 "tools.profiler.sampling"
190 } interactive-vocabs set-global
192 : loaded-vocab? ( vocab-spec -- ? )
194 [ find-vocab-root not ]
195 [ source-loaded?>> +done+ eq? ]
198 : use-loaded-vocabs ( vocabs -- )
201 dup loaded-vocab? [ use-vocab ] [ drop ] if
205 : with-interactive-vocabs ( quot -- )
207 "scratchpad" set-current-vocab
208 interactive-vocabs get use-loaded-vocabs
210 ] with-manifest ; inline
215 [ { } (listener) ] with-return
216 ] with-interactive-vocabs ;
218 : listener-main ( -- )
219 version-info print flush listener ;