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 ;
10 GENERIC: stream-read-quot ( stream -- quot/f )
12 : parse-lines-interactive ( lines -- quot/f )
13 [ parse-lines in get ] with-compilation-unit in set ;
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( error continuation -- ) ;
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?
67 : title. ( string -- )
68 H{ { foreground T{ rgba f 0.3 0.3 0.3 1 } } } format nl ;
70 : visible-vars. ( -- )
72 nl "--- Watched variables:" title.
73 standard-table-style [
76 [ [ short. ] with-cell ]
77 [ [ get short. ] with-cell ]
84 : trimmed-stack. ( seq -- )
85 dup length max-stack-items get > [
86 max-stack-items get cut*
88 [ length number>string "(" " more items)" surround ] keep
93 : datastack. ( datastack -- )
95 [ nl "--- Data stack:" title. trimmed-stack. ] unless-empty
99 in get auto-use? get [ " - auto" append ] when "( " " )" surround
100 H{ { background T{ rgba f 1 0.7 0.7 1 } } } format bl flush ;
102 :: (listener) ( datastack -- )
103 error-summary? get [ error-summary ] when
110 '[ datastack _ with-datastack ]
111 [ call-error-hook datastack ]
116 [ call-error-hook datastack ]
126 [ [ { } (listener) ] with-interactive-vocabs ] with-return ;