1 ! :folding=indent:collapseFolds=1:
5 ! Copyright (C) 2003, 2004 Slava Pestov.
7 ! Redistribution and use in source and binary forms, with or without
8 ! modification, are permitted provided that the following conditions are met:
10 ! 1. Redistributions of source code must retain the above copyright notice,
11 ! this list of conditions and the following disclaimer.
13 ! 2. Redistributions in binary form must reproduce the above copyright notice,
14 ! this list of conditions and the following disclaimer in the documentation
15 ! and/or other materials provided with the distribution.
17 ! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 ! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 ! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 ! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 ! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 ! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 ! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 ! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 SYMBOL: listener-prompt
49 "ok" listener-prompt set
53 "prompt" style write-attr
54 ! Print the space without a style, to workaround a bug in
55 ! the GUI listener where the style from the prompt carries
60 #! Exit the current listener.
63 : (read-multiline) ( quot depth -- quot ? )
64 #! Flag indicates EOF.
66 (parse) depth r> dup >r <= [
67 ( we're done ) r> drop t
69 ( more input needed ) r> cont-prompt get prompt.
76 : read-multiline ( -- quot ? )
77 #! Keep parsing until the end is reached. Flag indicates
79 f depth (read-multiline) >r reverse r> ;
82 #! Wait for user input, and execute.
83 listener-prompt get prompt.
84 [ read-multiline [ call ] [ exit ] ifte ] try ;
87 #! Run a listener loop that executes user input.
88 quit-flag get [ quit-flag off ] [ listen listener ] ifte ;
90 : kb. 1024 /i unparse write " KB" write ;
92 : (room.) ( free total -- )
93 2dup swap - swap ( free used total )
100 "Data space: " write (room.)
101 "Code space: " write (room.) ;
103 : print-banner ( -- )
104 "Factor " write version write
105 " (OS: " write os write
106 " CPU: " write cpu write
108 "Copyright (C) 2003, 2005 Slava Pestov" print
109 "Copyright (C) 2004, 2005 Chris Double" print
110 "Copyright (C) 2004, 2005 Mackenzie Straight" print
111 "Type ``exit'' to exit, ``help'' for help." print
118 "\"foo.image\" save-image -- save heap to a file" print
119 "room. -- show memory usage" print
120 "heap-stats. -- memory allocation breakdown" print
121 "garbage-collection -- force a GC" print
122 "exit -- exit interpreter" print
125 "vocabs. -- list vocabularies" print
126 "\"math\" words. -- list the math vocabulary" print
127 "\"str\" apropos. -- list all words containing str" print
128 "\\ neg see -- show word definition" print
129 "\\ car usages. -- list all words invoking car" print
132 ".s .r .n .c -- show contents of the 4 stacks" print
133 "clear -- clear datastack" print
136 "global describe -- list global variables." print
137 "\"foo\" get . -- print a variable value." print
138 ". -- print top of stack." print
140 "PROFILER: [ ... ] call-profile" print
141 " [ ... ] allot-profile" print
142 "TRACE: [ ... ] trace" print
143 "SINGLE STEP: [ ... ] walk" print
145 "HTTP SERVER: USE: httpd 8888 httpd" print
146 "TELNET SERVER: USE: telnetd 9999 telnetd" print ;
151 print-banner listener ;