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