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
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 ;
41 : bye ( -- ) quit-flag on ;
45 : show-var ( var -- ) visible-vars [ swap suffix ] change ;
47 : show-vars ( seq -- ) visible-vars [ swap union ] change ;
49 : hide-var ( var -- ) visible-vars [ remove ] change ;
51 : hide-vars ( seq -- ) visible-vars [ swap diff ] change ;
53 : hide-all-vars ( -- ) visible-vars off ;
57 : call-error-hook ( error -- )
58 error-continuation get error-hook get
59 call( error continuation -- ) ;
61 [ drop print-error-and-restarts ] error-hook set-global
63 SYMBOL: display-stacks?
65 t display-stacks? set-global
67 SYMBOL: max-stack-items
69 10 max-stack-items set-global
73 : title. ( string -- )
74 H{ { foreground T{ rgba f 0.3 0.3 0.3 1 } } } format nl ;
76 : visible-vars. ( -- )
78 nl "--- Watched variables:" title.
79 standard-table-style [
82 [ [ short. ] with-cell ]
83 [ [ get short. ] with-cell ]
90 : trimmed-stack. ( seq -- )
91 dup length max-stack-items get > [
92 max-stack-items get cut*
94 [ length number>string "(" " more items)" surround ] keep
100 display-stacks? get [
101 datastack [ nl "--- Data stack:" title. trimmed-stack. ] unless-empty
105 "( " in get auto-use? get [ " - auto" append ] when " )" 3append
106 H{ { background T{ rgba f 1 0.7 0.7 1 } } } format bl flush ;
109 visible-vars. stacks. prompt.
110 [ read-quot [ [ call-error-hook ] recover ] [ bye ] if* ]
111 [ dup lexer-error? [ call-error-hook ] [ rethrow ] if ] recover ;
114 quit-flag get [ quit-flag off ] [ listen until-quit ] if ;
119 [ until-quit ] with-interactive-vocabs ;