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 )
12 : parse-lines-interactive ( lines -- quot/f )
13 [ parse-lines ] with-compilation-unit ;
15 : read-quot-step ( lines -- quot/f )
16 [ parse-lines-interactive ] [
17 dup error>> unexpected-eof?
18 [ 2drop f ] [ rethrow ] if
21 : read-quot-loop ( stream accum -- quot/f )
22 over stream-readln dup [
24 dup read-quot-step dup
25 [ 2nip ] [ drop read-quot-loop ] if
30 M: object stream-read-quot
31 V{ } clone read-quot-loop ;
33 : read-quot ( -- quot/f ) input-stream get stream-read-quot ;
37 : show-var ( var -- ) visible-vars [ swap suffix ] change ;
39 : show-vars ( seq -- ) visible-vars [ swap union ] change ;
41 : hide-var ( var -- ) visible-vars [ remove ] change ;
43 : hide-vars ( seq -- ) visible-vars [ swap diff ] change ;
45 : hide-all-vars ( -- ) visible-vars off ;
49 : call-error-hook ( error -- )
50 error-continuation get error-hook get
51 call( continuation error -- ) ;
53 [ drop print-error-and-restarts ] error-hook set-global
55 SYMBOL: display-stacks?
57 t display-stacks? set-global
59 SYMBOL: max-stack-items
61 10 max-stack-items set-global
63 SYMBOL: error-summary?
65 t error-summary? set-global
69 : title. ( string -- )
70 H{ { foreground T{ rgba f 0.3 0.3 0.3 1 } } } format nl ;
72 : visible-vars. ( -- )
74 nl "--- Watched variables:" title.
75 standard-table-style [
78 [ [ short. ] with-cell ]
79 [ [ get short. ] with-cell ]
86 : trimmed-stack. ( seq -- )
87 dup length max-stack-items get > [
88 max-stack-items get cut*
90 [ length number>string "(" " more items)" surround ] keep
95 : datastack. ( datastack -- )
97 [ nl "--- Data stack:" title. trimmed-stack. ] unless-empty
101 current-vocab name>> auto-use? get [ " - auto" append ] when "( " " )" surround
102 H{ { background T{ rgba f 1 0.7 0.7 1 } } } format bl flush ;
104 :: (listener) ( datastack -- )
105 error-summary? get [ error-summary ] when
112 '[ datastack _ with-datastack ]
113 [ call-error-hook datastack ]
118 [ call-error-hook datastack ]
127 SYMBOL: interactive-vocabs
182 } interactive-vocabs set-global
184 : only-use-vocabs ( vocabs -- )
189 [ find-vocab-root not ]
190 [ source-loaded?>> +done+ eq? ] bi or
194 : with-interactive-vocabs ( quot -- )
196 "scratchpad" set-current-vocab
197 interactive-vocabs get only-use-vocabs
199 ] with-manifest ; inline
202 [ [ { } (listener) ] with-return ] with-interactive-vocabs ;