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