author | Claus Gittinger <cg@exept.de> |
Sat, 05 Nov 2016 12:56:52 +0100 | |
changeset 20836 | f3404ea02bb7 |
parent 20835 | ce8d50491138 |
child 20845 | d192dae88051 |
permissions | -rw-r--r-- |
10249 | 1 |
" |
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
16565 | 3 |
All Rights Reserved |
10249 | 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 |
||
19379 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
10248 | 16 |
Object subclass:#ReadEvalPrintLoop |
16228 | 17 |
instanceVariableNames:'inputStream outputStream errorStream compiler prompt |
20771 | 18 |
doChunkFormat traceFlag timingFlag profilingFlag printFlag |
19 |
exitAction currentDirectory' |
|
16228 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
22 |
category:'System-Support' |
|
10248 | 23 |
! |
24 |
||
10249 | 25 |
!ReadEvalPrintLoop class methodsFor:'documentation'! |
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
16565 | 30 |
All Rights Reserved |
10249 | 31 |
|
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
10461
0b2935207fec
+correctableError:position:to:
Claus Gittinger <cg@exept.de>
parents:
10277
diff
changeset
|
39 |
! |
0b2935207fec
+correctableError:position:to:
Claus Gittinger <cg@exept.de>
parents:
10277
diff
changeset
|
40 |
|
0b2935207fec
+correctableError:position:to:
Claus Gittinger <cg@exept.de>
parents:
10277
diff
changeset
|
41 |
documentation |
0b2935207fec
+correctableError:position:to:
Claus Gittinger <cg@exept.de>
parents:
10277
diff
changeset
|
42 |
" |
0b2935207fec
+correctableError:position:to:
Claus Gittinger <cg@exept.de>
parents:
10277
diff
changeset
|
43 |
A simple read-eval-print loop for non-GUI or stscript operation. |
16081 | 44 |
Invoked, for example if stx is started with a --repl argument. |
20833 | 45 |
|
10628
284266d54dbe
#exit only leaves the rep-loop
Claus Gittinger <cg@exept.de>
parents:
10500
diff
changeset
|
46 |
A line starting with '?' shows the usage message. |
284266d54dbe
#exit only leaves the rep-loop
Claus Gittinger <cg@exept.de>
parents:
10500
diff
changeset
|
47 |
Lines starting with '#' are directives: |
20833 | 48 |
#exit - exit the rep-loop |
49 |
type '?' to see more. |
|
50 |
||
16087 | 51 |
The input can be in one of two formats: |
20833 | 52 |
1) traditional chunk format (bang-separated chunks, bangs duplicated) |
53 |
this is the traditional fileIn format, as generated by fileOut from the browser |
|
16087 | 54 |
|
20833 | 55 |
2) interactive line mode. Chunks are any number of lines up to either an empty line or |
56 |
a line ending in a period. This is more useful for an interactive REPL, where statements/expressions |
|
57 |
are entered linewise by a user. |
|
16087 | 58 |
|
59 |
The input can is switched to non-chunk format whenever a line with a '#' in the first column appears. |
|
20833 | 60 |
|
61 |
[Author:] |
|
62 |
Claus Gittinger |
|
10461
0b2935207fec
+correctableError:position:to:
Claus Gittinger <cg@exept.de>
parents:
10277
diff
changeset
|
63 |
" |
10249 | 64 |
! ! |
10248 | 65 |
|
66 |
!ReadEvalPrintLoop methodsFor:'accessing'! |
|
67 |
||
10463 | 68 |
compiler:something |
16087 | 69 |
"assign a compiler to use;could be used to change the language" |
70 |
||
10463 | 71 |
compiler := something. |
10248 | 72 |
! |
73 |
||
10632 | 74 |
doChunkFormat |
16087 | 75 |
"true if currently reading chunk format" |
76 |
||
10632 | 77 |
^ doChunkFormat ? true |
78 |
||
79 |
"Created: / 07-12-2006 / 18:24:04 / cg" |
|
80 |
! |
|
81 |
||
16087 | 82 |
doChunkFormat:aBoolean |
83 |
"enable/disable chunk format" |
|
84 |
||
85 |
doChunkFormat := aBoolean. |
|
10254 | 86 |
|
87 |
"Created: / 07-12-2006 / 18:24:04 / cg" |
|
10248 | 88 |
! |
89 |
||
16087 | 90 |
error:aStream |
91 |
"assign an error stream" |
|
92 |
||
93 |
errorStream := aStream. |
|
10248 | 94 |
|
95 |
"Created: / 07-12-2006 / 17:33:39 / cg" |
|
96 |
! |
|
97 |
||
10463 | 98 |
errorStream |
16087 | 99 |
"return the current error stream" |
100 |
||
19379 | 101 |
errorStream notNil ifTrue:[^ errorStream]. |
102 |
^ Processor activeProcess stderr |
|
10256 | 103 |
|
19379 | 104 |
"Created: / 07-12-2006 / 19:12:27 / cg" |
10256 | 105 |
! |
106 |
||
16087 | 107 |
input:aStream |
108 |
"assign an input stream" |
|
109 |
||
110 |
inputStream := aStream asLineNumberReadStream. |
|
10248 | 111 |
|
112 |
"Modified: / 07-12-2006 / 17:33:31 / cg" |
|
113 |
! |
|
114 |
||
10463 | 115 |
inputStream |
16087 | 116 |
"get the current input stream" |
117 |
||
19379 | 118 |
inputStream notNil ifTrue:[^ inputStream]. |
119 |
^ Processor activeProcess stdin |
|
10463 | 120 |
|
121 |
"Created: / 07-12-2006 / 19:12:13 / cg" |
|
10256 | 122 |
! |
123 |
||
16087 | 124 |
output:aStream |
125 |
"assign an output stream" |
|
126 |
||
127 |
outputStream := aStream. |
|
10248 | 128 |
|
129 |
"Created: / 07-12-2006 / 17:27:48 / cg" |
|
130 |
! |
|
131 |
||
10463 | 132 |
outputStream |
19379 | 133 |
"return the current output stream" |
16087 | 134 |
|
19379 | 135 |
outputStream notNil ifTrue:[^ outputStream]. |
136 |
^ Processor activeProcess stdout |
|
10463 | 137 |
|
138 |
"Created: / 07-12-2006 / 19:12:27 / cg" |
|
139 |
! |
|
140 |
||
16087 | 141 |
prompt:aString |
142 |
"set the prompt" |
|
143 |
||
144 |
prompt := aString. |
|
10248 | 145 |
! ! |
146 |
||
10631 | 147 |
!ReadEvalPrintLoop methodsFor:'compiler interface-error handling'! |
148 |
||
149 |
correctableError:message position:pos1 to:pos2 from:aCompiler |
|
150 |
"compiler notifies us of an error - ignore it" |
|
151 |
||
15702 | 152 |
^ false "/ no correction |
10631 | 153 |
! |
154 |
||
155 |
correctableSelectorWarning:aString position:relPos to:relEndPos from:aCompiler |
|
156 |
"compiler notifies us of a warning - ignore it" |
|
157 |
||
158 |
^ false |
|
159 |
! |
|
160 |
||
13121
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
161 |
correctableWarning:message position:pos1 to:pos2 from:aCompiler |
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
162 |
"compiler notifies us of an error - ignore it" |
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
163 |
|
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
164 |
^ false |
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
165 |
|
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
166 |
"Created: / 02-11-2010 / 13:29:22 / cg" |
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
167 |
! |
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
168 |
|
10631 | 169 |
error:aString position:relPos to:relEndPos from:aCompiler |
170 |
"compiler notifies us of a warning - ignore it" |
|
171 |
||
172 |
^ false |
|
173 |
! |
|
174 |
||
175 |
unusedVariableWarning:aString position:relPos to:relEndPos from:aCompiler |
|
176 |
"compiler notifies us of a warning - ignore it" |
|
177 |
||
178 |
^ false |
|
179 |
! |
|
180 |
||
181 |
warning:aString position:relPos to:relEndPos from:aCompiler |
|
182 |
"compiler notifies us of a warning - ignore it" |
|
183 |
||
184 |
^ self |
|
185 |
! ! |
|
186 |
||
10255 | 187 |
!ReadEvalPrintLoop methodsFor:'directives'! |
188 |
||
10463 | 189 |
cmd_clear:lineStream |
10255 | 190 |
self cmd_setOrClear:lineStream to:false |
191 |
||
192 |
"Created: / 07-12-2006 / 19:04:50 / cg" |
|
193 |
! |
|
194 |
||
10463 | 195 |
cmd_exit:lineStream |
10628
284266d54dbe
#exit only leaves the rep-loop
Claus Gittinger <cg@exept.de>
parents:
10500
diff
changeset
|
196 |
exitAction value |
10463 | 197 |
|
198 |
"Created: / 07-12-2006 / 18:55:46 / cg" |
|
10255 | 199 |
! |
200 |
||
10463 | 201 |
cmd_help:lineStream |
202 |
self errorStream |
|
20771 | 203 |
nextPutAll: |
16084 | 204 |
'Everything entered up to an empty line or a line ending in "." is called a "chunk" and evaluated. |
10463 | 205 |
Lines starting with "#" are commands to the read-eval-print interpreter. |
206 |
||
207 |
Valid commands are: |
|
10635
c3c4fc186068
changed #interpreterLoopWith:
Claus Gittinger <cg@exept.de>
parents:
10632
diff
changeset
|
208 |
#help ............... this text |
c3c4fc186068
changed #interpreterLoopWith:
Claus Gittinger <cg@exept.de>
parents:
10632
diff
changeset
|
209 |
#exit ............... exit interpreter loop |
c3c4fc186068
changed #interpreterLoopWith:
Claus Gittinger <cg@exept.de>
parents:
10632
diff
changeset
|
210 |
#use <package>....... use (load) a package |
20771 | 211 |
stx:libwidg .............. GUI package |
212 |
stx:libtool .............. IDE tool package |
|
213 |
stx:goodies/regex ........ regex package |
|
214 |
stx:goodies/petitparser .. peg parser package |
|
16087 | 215 |
#read <filename>..... read another script or source file |
10635
c3c4fc186068
changed #interpreterLoopWith:
Claus Gittinger <cg@exept.de>
parents:
10632
diff
changeset
|
216 |
#show <what> ........ show info |
20771 | 217 |
variables .......... interpreter variables |
218 |
processes .......... processes |
|
219 |
memory ............. memory usage |
|
220 |
flags .............. flags |
|
221 |
modules ............ loaded modules |
|
20834 | 222 |
all ................ all of the above |
10635
c3c4fc186068
changed #interpreterLoopWith:
Claus Gittinger <cg@exept.de>
parents:
10632
diff
changeset
|
223 |
#set/clear <flag> ... set or clear a flag |
20771 | 224 |
trace .............. tracing execution |
225 |
timing ............. timing execution |
|
226 |
profiling .......... show execution profile |
|
227 |
chunkFormat ........ traditional bang chunk format input mode |
|
10257 | 228 |
|
16087 | 229 |
The MiniDebugger (if entered) shows its own help with "?". |
10255 | 230 |
' |
231 |
||
232 |
"Created: / 07-12-2006 / 18:54:20 / cg" |
|
233 |
! |
|
234 |
||
16087 | 235 |
cmd_read:lineStream |
236 |
|filename newInput savedPrompt savedPrint savedInput savedCurrentDirectory| |
|
237 |
||
238 |
lineStream skipSeparators. |
|
239 |
filename := lineStream upToEnd withoutSeparators. |
|
16133 | 240 |
filename isNil ifTrue:[ |
16565 | 241 |
'? which file?' errorPrintCR. |
242 |
^ self. |
|
16133 | 243 |
]. |
244 |
filename := filename withoutSeparators. |
|
245 |
filename isEmpty ifTrue:[ |
|
16565 | 246 |
'? which file?' errorPrintCR. |
247 |
^ self. |
|
16133 | 248 |
]. |
16087 | 249 |
|
250 |
filename := filename asFilename. |
|
251 |
filename isAbsolute ifFalse:[ |
|
16565 | 252 |
filename := currentDirectory construct:filename. |
16087 | 253 |
]. |
254 |
||
255 |
newInput := filename readStream. |
|
256 |
newInput isNil ifTrue:[ |
|
16565 | 257 |
('Could not find file: "',filename,'"') errorPrintCR. |
258 |
^ self. |
|
16087 | 259 |
]. |
260 |
||
261 |
[ |
|
16565 | 262 |
savedCurrentDirectory := currentDirectory. |
263 |
savedInput := inputStream. |
|
264 |
savedPrint := printFlag. |
|
265 |
savedPrompt := prompt. |
|
16087 | 266 |
|
16565 | 267 |
currentDirectory := filename directory. |
268 |
inputStream := newInput. |
|
16087 | 269 |
|
16565 | 270 |
self |
271 |
basicReadEvalPrintLoopWithInput:newInput |
|
272 |
output:outputStream |
|
273 |
error:errorStream |
|
274 |
compiler:compiler |
|
275 |
prompt:false |
|
276 |
print:false. |
|
16087 | 277 |
] ensure:[ |
16565 | 278 |
currentDirectory := savedCurrentDirectory. |
279 |
inputStream := savedInput. |
|
280 |
printFlag := savedPrint. |
|
281 |
prompt := savedPrompt |
|
16087 | 282 |
]. |
283 |
! |
|
284 |
||
10463 | 285 |
cmd_set:lineStream |
10255 | 286 |
self cmd_setOrClear:lineStream to:true |
287 |
||
288 |
"Modified: / 07-12-2006 / 19:04:46 / cg" |
|
289 |
! |
|
290 |
||
10463 | 291 |
cmd_setOrClear:lineStream to:aBoolean |
292 |
|what| |
|
293 |
||
294 |
lineStream skipSeparators. |
|
295 |
what := lineStream nextAlphaNumericWord. |
|
16133 | 296 |
what notNil ifTrue:[ |
20771 | 297 |
(what startsWith:'tra') ifTrue:[ |
298 |
traceFlag := aBoolean. |
|
299 |
^ self. |
|
300 |
]. |
|
301 |
(what startsWith:'tim') ifTrue:[ |
|
302 |
timingFlag := aBoolean. |
|
303 |
^ self. |
|
304 |
]. |
|
305 |
(what startsWith:'pro') ifTrue:[ |
|
306 |
profilingFlag := aBoolean. |
|
307 |
^ self. |
|
308 |
]. |
|
309 |
(what startsWith:'chunk') ifTrue:[ |
|
310 |
doChunkFormat := aBoolean. |
|
311 |
^ self. |
|
312 |
]. |
|
10463 | 313 |
]. |
16133 | 314 |
self errorStream nextPutLine:'? which flag ?'. |
10255 | 315 |
|
10256 | 316 |
"Modified: / 07-12-2006 / 19:13:34 / cg" |
10255 | 317 |
! |
318 |
||
10463 | 319 |
cmd_show:lineStream |
20834 | 320 |
|errStream what showAll printModule ok| |
10463 | 321 |
|
16087 | 322 |
errStream := self errorStream. |
323 |
||
10463 | 324 |
lineStream skipSeparators. |
325 |
what := lineStream nextAlphaNumericWord. |
|
20834 | 326 |
ok := false. |
327 |
||
16133 | 328 |
what notNil ifTrue:[ |
20834 | 329 |
showAll := (what startsWith:'all'). |
330 |
||
20835 | 331 |
(showAll or:[ what startsWith:'var' ]) ifTrue:[ |
332 |
showAll ifTrue:[ errStream nextPutLine:'Variables:'; nextPutLine:'----------' ]. |
|
20768 | 333 |
Workspace notNil ifTrue:[ |
20770 | 334 |
Workspace workspaceVariables keys asOrderedCollection sort do:[:nm | |
335 |
|holder| |
|
336 |
holder := Workspace workspaceVariables at:nm. |
|
337 |
errStream nextPutAll:nm; nextPutAll:' -> '; nextPutLine:holder value printString. |
|
20768 | 338 |
]. |
339 |
]. |
|
340 |
]. |
|
20835 | 341 |
(showAll or:[ what startsWith:'proc' ]) ifTrue:[ |
20836 | 342 |
showAll ifTrue:[ errStream cr; nextPutLine:'Threads:'; nextPutLine:'--------' ]. |
20768 | 343 |
MiniDebugger basicNew showProcesses. |
344 |
]. |
|
20834 | 345 |
(showAll or:[ what startsWith:'mod' ]) ifTrue:[ |
20836 | 346 |
showAll ifTrue:[ errStream cr; nextPutLine:'Modules:'; nextPutLine:'--------' ]. |
20768 | 347 |
printModule := |
348 |
[:mod | |
|
349 |
errStream |
|
350 |
nextPutAll:' '; |
|
351 |
nextPutAll:(mod package "libraryName"); |
|
352 |
nextPutLine:' (',(mod type),')'. |
|
353 |
]. |
|
13865 | 354 |
|
20768 | 355 |
errStream nextPutLine:'builtIn:'. |
356 |
((ObjectMemory binaryModuleInfo |
|
357 |
reject:[:m | m dynamic]) |
|
358 |
asSortedCollection:[:a :b | a name < b name]) do:printModule. |
|
13865 | 359 |
|
20768 | 360 |
errStream nextPutLine:'dynamic:'. |
361 |
((ObjectMemory binaryModuleInfo |
|
362 |
select:[:m | m dynamic]) |
|
363 |
asSortedCollection:[:a :b | a name < b name]) do:printModule. |
|
13865 | 364 |
|
20768 | 365 |
]. |
20834 | 366 |
(showAll or:[ what startsWith:'mem' ]) ifTrue:[ |
367 |
|allMem| |
|
368 |
||
20836 | 369 |
showAll ifTrue:[ errStream cr; nextPutLine:'Memory:'; nextPutLine:'-------' ]. |
20834 | 370 |
allMem := ObjectMemory oldSpaceUsed + ObjectMemory symSpaceUsed |
20768 | 371 |
+ ObjectMemory newSpaceUsed. |
372 |
errStream |
|
20834 | 373 |
nextPutLine:('overall: ',(allMem // 1024) printString,' Kb'); |
20768 | 374 |
nextPutLine:('in use : ',(ObjectMemory bytesUsed // 1024) printString,' Kb'); |
375 |
nextPutLine:('free : ',(ObjectMemory freeSpace // 1024) printString,' Kb'); |
|
376 |
nextPutLine:('minorGC: ',(ObjectMemory scavengeCount) printString); |
|
377 |
nextPutLine:('majorGC: ',(ObjectMemory garbageCollectCount) printString). |
|
378 |
]. |
|
20834 | 379 |
(showAll or:[ what startsWith:'flag' ]) ifTrue:[ |
20836 | 380 |
showAll ifTrue:[ errStream cr; nextPutLine:'Flags:'; nextPutLine:'------' ]. |
20768 | 381 |
errStream |
382 |
nextPutLine:('trace : ',traceFlag printString); |
|
383 |
nextPutLine:('timing: ',timingFlag printString); |
|
384 |
nextPutLine:('chunkFormat: ',doChunkFormat printString). |
|
385 |
]. |
|
10463 | 386 |
]. |
387 |
||
20834 | 388 |
ok ifFalse:[ |
389 |
errStream nextPutLine:'? show what ?'. |
|
390 |
]. |
|
391 |
||
392 |
" |
|
393 |
self basicNew cmd_show:'packages' readStream |
|
394 |
" |
|
10255 | 395 |
|
13866 | 396 |
"Modified: / 07-12-2011 / 22:15:07 / cg" |
10255 | 397 |
! |
398 |
||
10463 | 399 |
cmd_use:lineStream |
16145 | 400 |
|pkg| |
10463 | 401 |
|
402 |
lineStream skipSeparators. |
|
16133 | 403 |
pkg := lineStream upToEnd. |
404 |
pkg isNil ifTrue:[ |
|
16565 | 405 |
'? which package?' errorPrintCR. |
406 |
^ self. |
|
16133 | 407 |
]. |
408 |
pkg := pkg withoutSeparators. |
|
409 |
pkg isEmpty ifTrue:[ |
|
16565 | 410 |
'? which package?' errorPrintCR. |
411 |
^ self. |
|
16133 | 412 |
]. |
413 |
||
16145 | 414 |
[ |
16565 | 415 |
Smalltalk loadPackage:pkg. |
16145 | 416 |
] on:PackageLoadError do:[:ex| |
16565 | 417 |
"/ allow for some shortcuts... |
418 |
(pkg includes:$:) ifTrue:[ |
|
419 |
self errorStream nextPutLine:('Failed to load package: "',pkg,'"'). |
|
420 |
] ifFalse:[ |
|
421 |
"/ try stx standard package |
|
422 |
pkg := 'stx:', pkg. |
|
423 |
ex restart. |
|
424 |
]. |
|
13852 | 425 |
]. |
10255 | 426 |
|
427 |
"Created: / 07-12-2006 / 19:07:56 / cg" |
|
10463 | 428 |
! |
429 |
||
430 |
directive:line |
|
431 |
|s cmd| |
|
432 |
||
433 |
s := line readStream. |
|
434 |
s next. "/ skip the hash |
|
435 |
s skipSeparators. |
|
436 |
||
437 |
cmd := s nextAlphaNumericWord. |
|
16087 | 438 |
cmd notNil ifTrue:[ |
16565 | 439 |
self |
440 |
perform:('cmd_',cmd) asMutator with:s |
|
441 |
ifNotUnderstood:[ |
|
442 |
self errorStream |
|
443 |
nextPutAll:'?? invalid command: '; |
|
444 |
nextPutAll:cmd; |
|
445 |
nextPutAll:'. Type "#help" for help.'; |
|
446 |
cr. |
|
447 |
]. |
|
16087 | 448 |
]. |
10463 | 449 |
|
450 |
"Created: / 07-12-2006 / 18:49:17 / cg" |
|
10255 | 451 |
! ! |
452 |
||
10248 | 453 |
!ReadEvalPrintLoop methodsFor:'evaluation'! |
454 |
||
16565 | 455 |
basicReadEvalPrintLoopWithInput:input output:output error:error |
16087 | 456 |
compiler:compilerClass prompt:prompt print:doPrint |
457 |
||
458 |
"{ Pragma: +optSpace }" |
|
459 |
||
460 |
"the core of the interpreter loop; extracted and parametrized, so it can be called recursive |
|
461 |
for included scripts. |
|
462 |
If chunkFormat is true, chunks are read. |
|
463 |
Otherwise, lines up to an empty line (or EOF) or a line ending in '.' are read. |
|
20774 | 464 |
A '#' character appearing in the first column of the first line turns off chunkmode, |
465 |
which allows for convenient shell scripts containing a #/bin/stx as the first line." |
|
16087 | 466 |
|
467 |
[ |
|
20769 | 468 |
|lines chunk| |
16087 | 469 |
|
20769 | 470 |
prompt notNil ifTrue:[ |
471 |
error nextPutAll:prompt. |
|
472 |
]. |
|
16087 | 473 |
|
20769 | 474 |
input atEnd ifTrue:[ |
475 |
error cr. |
|
476 |
^ self. |
|
477 |
]. |
|
16087 | 478 |
|
20769 | 479 |
input peek == $# ifTrue:[ |
480 |
self doChunkFormat:false. |
|
481 |
]. |
|
16087 | 482 |
|
20769 | 483 |
self doChunkFormat ifTrue:[ |
484 |
input skipSeparators. |
|
485 |
chunk := input nextChunk. |
|
486 |
] ifFalse:[ |
|
487 |
lines := OrderedCollection new. |
|
488 |
[ |
|
489 |
|line| |
|
16087 | 490 |
|
20769 | 491 |
line := input nextLine. |
492 |
line notEmptyOrNil ifTrue:[ |
|
493 |
line = '?' ifTrue:[ |
|
494 |
self cmd_help:nil. |
|
495 |
prompt notNil ifTrue:[ |
|
496 |
error nextPutAll:prompt. |
|
497 |
]. |
|
498 |
] ifFalse:[ |
|
499 |
(line startsWith:'#') ifTrue:[ |
|
500 |
self directive:line. |
|
501 |
prompt notNil ifTrue:[ |
|
502 |
error nextPutAll:prompt. |
|
503 |
]. |
|
504 |
] ifFalse:[ |
|
505 |
lines add:line. |
|
506 |
] |
|
507 |
] |
|
508 |
]. |
|
509 |
line notEmptyOrNil and:[(line endsWith:$.) not]. |
|
510 |
] whileTrue. |
|
511 |
chunk := lines asStringWith:Character cr. |
|
512 |
]. |
|
16087 | 513 |
|
20769 | 514 |
(chunk notEmptyOrNil and:[chunk withoutSeparators notEmpty]) ifTrue:[ |
515 |
"abortAll is handled, but not asked for here!!" |
|
516 |
AbortAllOperationRequest handle:[:ex | |
|
517 |
error nextPutLine:('Evaluation aborted: ', ex description) |
|
518 |
] do:[ |
|
519 |
(Error, ControlInterrupt) handle:[:ex | |
|
520 |
prompt isNil ifTrue:[ |
|
521 |
ex reject |
|
522 |
]. |
|
523 |
MiniDebugger enterWithMessage:(ex errorString) mayProceed:true. |
|
524 |
ex mayProceed ifTrue:[ |
|
525 |
ex proceed. |
|
526 |
]. |
|
527 |
error nextPutLine:('Evaluation aborted: ', ex description). |
|
528 |
ex return. |
|
529 |
] do:[ |
|
530 |
|value ms us| |
|
16087 | 531 |
|
20771 | 532 |
profilingFlag == true ifTrue:[ |
533 |
MessageTally spyDetailedOn:[ |
|
534 |
value := (compilerClass new requestor:self) |
|
535 |
evaluate:chunk |
|
536 |
compile:true. |
|
537 |
]. |
|
538 |
doPrint ifTrue:[ |
|
539 |
value printOn:output. output cr. |
|
540 |
]. |
|
541 |
] ifFalse:[ |
|
542 |
us := Time microsecondsToRun:[ |
|
543 |
value := (compilerClass new requestor:self) |
|
544 |
evaluate:chunk compile:true. |
|
545 |
]. |
|
546 |
doPrint ifTrue:[ |
|
547 |
value printOn:output. output cr. |
|
548 |
]. |
|
16087 | 549 |
|
20771 | 550 |
timingFlag == true ifTrue:[ |
551 |
'execution time: ' printOn:error. |
|
552 |
us < 1000 ifTrue:[ |
|
553 |
us < 1 ifTrue:[ |
|
554 |
'too small to measure (<1us)' printOn:error. |
|
555 |
] ifFalse:[ |
|
556 |
us printOn:output. 'us' printOn:error. |
|
557 |
] |
|
20769 | 558 |
] ifFalse:[ |
20771 | 559 |
((us / 1000) asFixedPoint:2) printOn:output. 'ms' printOn:error. |
560 |
]. |
|
561 |
error cr. |
|
20769 | 562 |
]. |
563 |
]. |
|
564 |
Workspace notNil ifTrue:[ |
|
565 |
Workspace rememberResultAsWorkspaceVariable:value. |
|
566 |
]. |
|
567 |
]. |
|
568 |
]. |
|
569 |
]. |
|
16087 | 570 |
] loop. |
571 |
||
572 |
" |
|
573 |
(ReadEvalPrintLoop new prompt:'>') readEvalPrintLoop |
|
574 |
" |
|
575 |
||
576 |
"Created: / 07-12-2006 / 17:27:21 / cg" |
|
577 |
"Modified: / 06-12-2011 / 15:29:03 / cg" |
|
578 |
! |
|
579 |
||
10463 | 580 |
readEvalPrintLoop |
581 |
"{ Pragma: +optSpace }" |
|
582 |
||
583 |
"simple read-eval-print loop for non-graphical Minitalk. |
|
584 |
If the chunkFormat-argument is true, chunks are read. |
|
16087 | 585 |
Otherwise, lines up to an empty line (or EOF) are read. |
586 |
A '#' character appearing in the first column of the first line |
|
587 |
switches to chunkmode." |
|
10463 | 588 |
|
10628
284266d54dbe
#exit only leaves the rep-loop
Claus Gittinger <cg@exept.de>
parents:
10500
diff
changeset
|
589 |
exitAction := [^ self]. |
284266d54dbe
#exit only leaves the rep-loop
Claus Gittinger <cg@exept.de>
parents:
10500
diff
changeset
|
590 |
|
10463 | 591 |
ControlInterrupt handle:[:ex | |
20774 | 592 |
self errorStream nextPutLine:('Caught: ', ex description). |
20833 | 593 |
self inputStream atEnd ifTrue:[ |
594 |
ex return. |
|
595 |
]. |
|
20774 | 596 |
ex restart. |
10463 | 597 |
] do:[ |
20774 | 598 |
|input output error compilerClass| |
599 |
||
600 |
"/ re-evaluate these in the loop, so they can be changed dynamically |
|
601 |
input := self inputStream. |
|
602 |
output := self outputStream. |
|
603 |
error := self errorStream. |
|
10463 | 604 |
|
20774 | 605 |
compilerClass := compiler ? Compiler ? Parser. |
606 |
compilerClass isNil ifTrue:[ |
|
607 |
self errorStream nextPutLine:('oops - no Compiler class found'). |
|
608 |
^ self. |
|
609 |
]. |
|
610 |
StreamError handle:[:ex | |
|
611 |
(input isOpen not or:[input atEnd]) ifTrue:[ |
|
612 |
error nextPutLine:'EOF on input'. |
|
20833 | 613 |
ex return. |
20774 | 614 |
]. |
615 |
(output isOpen not) ifTrue:[ |
|
616 |
error nextPutLine:'no output'. |
|
617 |
]. |
|
618 |
(error isOpen not) ifTrue:[ |
|
619 |
]. |
|
620 |
] do:[ |
|
621 |
input signalAtEnd:true. |
|
622 |
self |
|
623 |
basicReadEvalPrintLoopWithInput:input output:output error:error |
|
624 |
compiler:compilerClass prompt:prompt print:(printFlag ? true). |
|
625 |
] |
|
10463 | 626 |
] |
627 |
||
628 |
" |
|
629 |
(ReadEvalPrintLoop new prompt:'>') readEvalPrintLoop |
|
630 |
" |
|
631 |
||
632 |
"Created: / 07-12-2006 / 17:27:21 / cg" |
|
13859
81451e09af8d
changed: #readEvalPrintLoop
Claus Gittinger <cg@exept.de>
parents:
13858
diff
changeset
|
633 |
"Modified: / 06-12-2011 / 15:29:03 / cg" |
10248 | 634 |
! ! |
635 |
||
16089 | 636 |
!ReadEvalPrintLoop methodsFor:'queries'! |
637 |
||
638 |
autoDefineVariables |
|
639 |
"when evaluating with --eval, auto define any variables" |
|
640 |
||
641 |
^ #workspace |
|
642 |
! ! |
|
643 |
||
10248 | 644 |
!ReadEvalPrintLoop class methodsFor:'documentation'! |
645 |
||
646 |
version |
|
19379 | 647 |
^ '$Header$' |
13121
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
648 |
! |
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
649 |
|
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
650 |
version_CVS |
19379 | 651 |
^ '$Header$' |
10248 | 652 |
! ! |
19379 | 653 |