10249
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2006 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
10248
|
12 |
"{ Package: 'stx:libbasic' }"
|
|
13 |
|
|
14 |
Object subclass:#ReadEvalPrintLoop
|
10254
|
15 |
instanceVariableNames:'inputStream outputStream errorStream compiler prompt
|
10255
|
16 |
doChunkFormat traceFlag timingFlag'
|
10248
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'* uncategorized *'
|
|
20 |
!
|
|
21 |
|
10249
|
22 |
!ReadEvalPrintLoop class methodsFor:'documentation'!
|
|
23 |
|
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 2006 by eXept Software AG
|
|
27 |
All Rights Reserved
|
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
! !
|
10248
|
37 |
|
|
38 |
!ReadEvalPrintLoop methodsFor:'accessing'!
|
|
39 |
|
10254
|
40 |
compiler:something
|
|
41 |
compiler := something.
|
10248
|
42 |
!
|
|
43 |
|
10254
|
44 |
doChunkFormat:something
|
|
45 |
doChunkFormat := something.
|
|
46 |
|
|
47 |
"Created: / 07-12-2006 / 18:24:04 / cg"
|
10248
|
48 |
!
|
|
49 |
|
|
50 |
error:something
|
|
51 |
errorStream := something.
|
|
52 |
|
|
53 |
"Created: / 07-12-2006 / 17:33:39 / cg"
|
|
54 |
!
|
|
55 |
|
10256
|
56 |
errorStream
|
|
57 |
^ errorStream ? Transcript ? Stderr
|
|
58 |
|
|
59 |
"Created: / 07-12-2006 / 19:11:56 / cg"
|
|
60 |
!
|
|
61 |
|
10248
|
62 |
input:something
|
|
63 |
inputStream := something.
|
|
64 |
|
|
65 |
"Modified: / 07-12-2006 / 17:33:31 / cg"
|
|
66 |
!
|
|
67 |
|
10256
|
68 |
inputStream
|
|
69 |
^ inputStream ? Stdin
|
|
70 |
|
|
71 |
"Created: / 07-12-2006 / 19:12:13 / cg"
|
|
72 |
!
|
|
73 |
|
10248
|
74 |
output:something
|
|
75 |
outputStream := something.
|
|
76 |
|
|
77 |
"Created: / 07-12-2006 / 17:27:48 / cg"
|
|
78 |
!
|
|
79 |
|
10256
|
80 |
outputStream
|
|
81 |
^ outputStream ? Stdout
|
|
82 |
|
|
83 |
"Created: / 07-12-2006 / 19:12:27 / cg"
|
|
84 |
!
|
|
85 |
|
10248
|
86 |
prompt:something
|
|
87 |
prompt := something.
|
|
88 |
! !
|
|
89 |
|
10255
|
90 |
!ReadEvalPrintLoop methodsFor:'directives'!
|
|
91 |
|
|
92 |
cmd_clear:lineStream
|
|
93 |
self cmd_setOrClear:lineStream to:false
|
|
94 |
|
|
95 |
"Created: / 07-12-2006 / 19:04:50 / cg"
|
|
96 |
!
|
|
97 |
|
|
98 |
cmd_exit:lineStream
|
|
99 |
Smalltalk exit
|
|
100 |
|
|
101 |
"Created: / 07-12-2006 / 18:55:46 / cg"
|
|
102 |
!
|
|
103 |
|
|
104 |
cmd_help:lineStream
|
10256
|
105 |
self errorStream
|
10255
|
106 |
nextPutAll:
|
|
107 |
'Everything entered up to an empty line is called a "chunk" and evaluated as a block.
|
|
108 |
Lines starting with "#" are commands to the read-eval-print interpreter.
|
|
109 |
|
|
110 |
Valid commands are:
|
|
111 |
help ............... this text
|
|
112 |
exit ............... exit smalltalk
|
|
113 |
use <package>....... use a package
|
|
114 |
stx:libwidg ........ GUI package
|
|
115 |
stx:libtool ........ IDE tool package
|
|
116 |
show <what> ........ show info
|
|
117 |
variables .......... interpreter variables
|
|
118 |
processes .......... processes
|
|
119 |
memory ............. memory usage
|
|
120 |
flags .............. flags
|
|
121 |
set/clear <flag> ... set or clear a flag
|
|
122 |
trace .............. tracing execution
|
|
123 |
timing ............. timing execution
|
10257
|
124 |
|
|
125 |
MiniDebugger shows its help with "?".
|
10255
|
126 |
'
|
|
127 |
|
|
128 |
"Created: / 07-12-2006 / 18:54:20 / cg"
|
|
129 |
!
|
|
130 |
|
|
131 |
cmd_set:lineStream
|
|
132 |
self cmd_setOrClear:lineStream to:true
|
|
133 |
|
|
134 |
"Modified: / 07-12-2006 / 19:04:46 / cg"
|
|
135 |
!
|
|
136 |
|
|
137 |
cmd_setOrClear:lineStream to:aBoolean
|
|
138 |
|what|
|
|
139 |
|
|
140 |
lineStream skipSeparators.
|
|
141 |
what := lineStream nextAlphaNumericWord.
|
|
142 |
(what startsWith:'tra') ifTrue:[
|
|
143 |
traceFlag := aBoolean.
|
|
144 |
^ self.
|
|
145 |
].
|
|
146 |
(what startsWith:'tim') ifTrue:[
|
|
147 |
timingFlag := aBoolean.
|
|
148 |
^ self.
|
|
149 |
].
|
|
150 |
|
10256
|
151 |
self errorStream nextPutLine:'?? which flag ?'.
|
10255
|
152 |
|
10256
|
153 |
"Modified: / 07-12-2006 / 19:13:34 / cg"
|
10255
|
154 |
!
|
|
155 |
|
|
156 |
cmd_show:lineStream
|
|
157 |
|what|
|
|
158 |
|
|
159 |
lineStream skipSeparators.
|
|
160 |
what := lineStream nextAlphaNumericWord.
|
|
161 |
(what startsWith:'var') ifTrue:[
|
|
162 |
^ self.
|
|
163 |
].
|
|
164 |
(what startsWith:'proc') ifTrue:[
|
|
165 |
MiniDebugger basicNew showProcesses.
|
|
166 |
^ self.
|
|
167 |
].
|
|
168 |
(what startsWith:'mem') ifTrue:[
|
10256
|
169 |
self errorStream
|
10261
|
170 |
nextPutLine:('overall: ',(ObjectMemory bytesUsed // 1024) printString,' Kb');
|
|
171 |
nextPutLine:('free : ',(ObjectMemory freeSpace // 1024) printString,' Kb');
|
10259
|
172 |
nextPutLine:('minorGC: ',(ObjectMemory scavengeCount) printString);
|
|
173 |
nextPutLine:('majorGC: ',(ObjectMemory garbageCollectCount) printString).
|
10255
|
174 |
^ self.
|
|
175 |
].
|
|
176 |
(what startsWith:'flag') ifTrue:[
|
10256
|
177 |
self errorStream
|
10259
|
178 |
nextPutLine:('trace : ',traceFlag printString);
|
|
179 |
nextPutLine:('timing: ',timingFlag printString).
|
10255
|
180 |
^ self.
|
|
181 |
].
|
|
182 |
|
10256
|
183 |
self errorStream nextPutLine:'?? show what ?'.
|
10255
|
184 |
|
10261
|
185 |
"Modified: / 07-12-2006 / 19:23:15 / cg"
|
10255
|
186 |
!
|
|
187 |
|
|
188 |
cmd_use:lineStream
|
|
189 |
|pkg|
|
|
190 |
|
|
191 |
lineStream skipSeparators.
|
|
192 |
pkg := lineStream upToEnd withoutSeparators.
|
|
193 |
Smalltalk loadPackage:pkg
|
|
194 |
|
|
195 |
"Created: / 07-12-2006 / 19:07:56 / cg"
|
|
196 |
!
|
|
197 |
|
|
198 |
directive:line
|
|
199 |
|s cmd|
|
|
200 |
|
|
201 |
s := line readStream.
|
|
202 |
s next. "/ skip the hash
|
|
203 |
s skipSeparators.
|
|
204 |
|
|
205 |
cmd := s nextAlphaNumericWord.
|
|
206 |
self
|
|
207 |
perform:('cmd_',cmd,':') asSymbol with:s
|
|
208 |
ifNotUnderstood:[
|
10256
|
209 |
self errorStream
|
10255
|
210 |
nextPutAll:'?? invalid command: ';
|
|
211 |
nextPutAll:cmd;
|
|
212 |
nextPutAll:'. Type "#help" for help.';
|
|
213 |
cr.
|
|
214 |
].
|
|
215 |
|
|
216 |
"Created: / 07-12-2006 / 18:49:17 / cg"
|
|
217 |
! !
|
|
218 |
|
10248
|
219 |
!ReadEvalPrintLoop methodsFor:'evaluation'!
|
|
220 |
|
|
221 |
readEvalPrintLoop
|
|
222 |
"{ Pragma: +optSpace }"
|
|
223 |
|
|
224 |
"simple read-eval-print loop for non-graphical Minitalk.
|
|
225 |
If the chunkFormat-argument is true, chunks are read.
|
|
226 |
Otherwise, lines up to an empty line (or EOF) are read."
|
|
227 |
|
|
228 |
[
|
10252
|
229 |
|input output error lines chunk compilerClass|
|
10248
|
230 |
|
10256
|
231 |
"/ re-evaluate these in the loop, so they can be changed dynamically
|
|
232 |
input := self inputStream.
|
|
233 |
output := self outputStream.
|
|
234 |
error := self errorStream.
|
10252
|
235 |
compilerClass := compiler ? Compiler.
|
10248
|
236 |
|
|
237 |
prompt notNil ifTrue:[
|
10258
|
238 |
error nextPutAll:prompt.
|
10248
|
239 |
].
|
|
240 |
|
|
241 |
input atEnd ifTrue:[
|
|
242 |
^ self.
|
|
243 |
].
|
|
244 |
|
10254
|
245 |
(doChunkFormat ? true) ifTrue:[
|
10248
|
246 |
input skipSeparators.
|
|
247 |
chunk := input nextChunk.
|
|
248 |
] ifFalse:[
|
|
249 |
lines := OrderedCollection new.
|
|
250 |
[
|
|
251 |
|line|
|
|
252 |
|
|
253 |
line := input nextLine.
|
|
254 |
line notEmptyOrNil ifTrue:[
|
10257
|
255 |
line = '?' ifTrue:[
|
10258
|
256 |
self cmd_help:nil.
|
|
257 |
prompt notNil ifTrue:[
|
|
258 |
error nextPutAll:prompt.
|
|
259 |
].
|
10255
|
260 |
] ifFalse:[
|
10257
|
261 |
(line startsWith:'#') ifTrue:[
|
10258
|
262 |
self directive:line.
|
|
263 |
prompt notNil ifTrue:[
|
|
264 |
error nextPutAll:prompt.
|
|
265 |
].
|
10257
|
266 |
] ifFalse:[
|
|
267 |
lines add:line.
|
|
268 |
]
|
10248
|
269 |
]
|
|
270 |
].
|
|
271 |
line notEmptyOrNil.
|
|
272 |
] whileTrue.
|
|
273 |
chunk := lines asStringWith:Character cr.
|
|
274 |
].
|
|
275 |
|
|
276 |
chunk notEmptyOrNil ifTrue:[
|
|
277 |
AbortAllOperationRequest handle:[:ex |
|
|
278 |
error nextPutLine:('Evaluation aborted: ', ex description)
|
|
279 |
] do:[
|
|
280 |
|value|
|
|
281 |
|
10262
|
282 |
value := (compilerClass new requestor:self) evaluate:chunk compile:true.
|
10253
|
283 |
value printOn:output.
|
|
284 |
output cr.
|
10248
|
285 |
].
|
|
286 |
].
|
|
287 |
] loop.
|
|
288 |
|
10252
|
289 |
"
|
|
290 |
(ReadEvalPrintLoop new prompt:'>') readEvalPrintLoop
|
|
291 |
"
|
|
292 |
|
10248
|
293 |
"Created: / 07-12-2006 / 17:27:21 / cg"
|
10262
|
294 |
"Modified: / 07-12-2006 / 19:29:01 / cg"
|
10248
|
295 |
! !
|
|
296 |
|
|
297 |
!ReadEvalPrintLoop class methodsFor:'documentation'!
|
|
298 |
|
|
299 |
version
|
10262
|
300 |
^ '$Header: /cvs/stx/stx/libbasic/ReadEvalPrintLoop.st,v 1.13 2006-12-07 18:28:27 cg Exp $'
|
10248
|
301 |
! !
|