1 ! Copyright (C) 2003, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays hashtables io kernel math math.parser memory
4 namespaces parser lexer sequences strings io.styles
5 vectors words generic system combinators continuations debugger
6 definitions compiler.units accessors colors prettyprint fry
7 sets vocabs.parser source-files.errors locals vocabs vocabs.loader ;
10 GENERIC: stream-read-quot ( stream -- quot/f )
11 GENERIC# prompt. 1 ( stream prompt -- )
14 current-vocab name>> auto-use? get [ " - auto" append ] when
18 nip H{ { background T{ rgba f 1 0.7 0.7 1 } } } format bl
21 : parse-lines-interactive ( lines -- quot/f )
22 [ parse-lines ] with-compilation-unit ;
24 : read-quot-step ( lines -- quot/f )
25 [ parse-lines-interactive ] [
26 dup error>> unexpected-eof?
27 [ 2drop f ] [ rethrow ] if
30 : read-quot-loop ( stream accum -- quot/f )
31 over stream-readln dup [
33 dup read-quot-step dup
34 [ 2nip ] [ drop read-quot-loop ] if
39 M: object stream-read-quot
40 V{ } clone read-quot-loop ;
42 : read-quot ( -- quot/f ) input-stream get stream-read-quot ;
46 : show-var ( var -- ) visible-vars [ swap suffix ] change ;
48 : show-vars ( seq -- ) visible-vars [ swap union ] change ;
50 : hide-var ( var -- ) visible-vars [ remove ] change ;
52 : hide-vars ( seq -- ) visible-vars [ swap diff ] change ;
54 : hide-all-vars ( -- ) visible-vars off ;
58 : call-error-hook ( error -- )
59 error-continuation get error-hook get
60 call( continuation error -- ) ;
62 [ drop print-error-and-restarts ] error-hook set-global
64 SYMBOL: display-stacks?
66 t display-stacks? set-global
68 SYMBOL: max-stack-items
70 10 max-stack-items set-global
72 SYMBOL: error-summary?
74 t error-summary? set-global
78 : title. ( string -- )
79 H{ { foreground T{ rgba f 0.3 0.3 0.3 1 } } } format nl ;
81 : visible-vars. ( -- )
83 nl "--- Watched variables:" title.
84 standard-table-style [
87 [ [ short. ] with-cell ]
88 [ [ get short. ] with-cell ]
95 : trimmed-stack. ( seq -- )
96 dup length max-stack-items get > [
97 max-stack-items get cut*
99 [ length number>string "(" " more items)" surround ] keep
104 : datastack. ( datastack -- )
105 display-stacks? get [
106 [ nl "--- Data stack:" title. trimmed-stack. ] unless-empty
109 :: (listener) ( datastack -- )
110 error-summary? get [ error-summary ] when
113 input-stream get prompt prompt.
117 '[ datastack _ with-datastack ]
118 [ call-error-hook datastack ]
123 [ call-error-hook datastack ]
132 SYMBOL: interactive-vocabs
187 } interactive-vocabs set-global
189 : only-use-vocabs ( vocabs -- )
194 [ find-vocab-root not ]
195 [ source-loaded?>> +done+ eq? ] bi or
199 : with-interactive-vocabs ( quot -- )
201 "scratchpad" set-current-vocab
202 interactive-vocabs get only-use-vocabs
204 ] with-manifest ; inline
207 [ [ { } (listener) ] with-return ] with-interactive-vocabs ;