author | Claus Gittinger <cg@exept.de> |
Thu, 03 Nov 2016 23:00:20 +0100 | |
changeset 20771 | bc02f6854efa |
parent 20770 | 46d2fd1b00a5 |
child 20774 | a29ae1f5f429 |
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. |
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 |
|
20771 | 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 |
20771 | 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 |
20771 | 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 |
20771 | 219 |
trace .............. tracing execution |
220 |
timing ............. timing execution |
|
221 |
profiling .......... show execution profile |
|
222 |
chunkFormat ........ traditional bang chunk format input mode |
|
10257 | 223 |
|
16087 | 224 |
The MiniDebugger (if entered) shows its own help with "?". |
10255 | 225 |
' |
226 |
||
227 |
"Created: / 07-12-2006 / 18:54:20 / cg" |
|
228 |
! |
|
229 |
||
16087 | 230 |
cmd_read:lineStream |
231 |
|filename newInput savedPrompt savedPrint savedInput savedCurrentDirectory| |
|
232 |
||
233 |
lineStream skipSeparators. |
|
234 |
filename := lineStream upToEnd withoutSeparators. |
|
16133 | 235 |
filename isNil ifTrue:[ |
16565 | 236 |
'? which file?' errorPrintCR. |
237 |
^ self. |
|
16133 | 238 |
]. |
239 |
filename := filename withoutSeparators. |
|
240 |
filename isEmpty ifTrue:[ |
|
16565 | 241 |
'? which file?' errorPrintCR. |
242 |
^ self. |
|
16133 | 243 |
]. |
16087 | 244 |
|
245 |
filename := filename asFilename. |
|
246 |
filename isAbsolute ifFalse:[ |
|
16565 | 247 |
filename := currentDirectory construct:filename. |
16087 | 248 |
]. |
249 |
||
250 |
newInput := filename readStream. |
|
251 |
newInput isNil ifTrue:[ |
|
16565 | 252 |
('Could not find file: "',filename,'"') errorPrintCR. |
253 |
^ self. |
|
16087 | 254 |
]. |
255 |
||
256 |
[ |
|
16565 | 257 |
savedCurrentDirectory := currentDirectory. |
258 |
savedInput := inputStream. |
|
259 |
savedPrint := printFlag. |
|
260 |
savedPrompt := prompt. |
|
16087 | 261 |
|
16565 | 262 |
currentDirectory := filename directory. |
263 |
inputStream := newInput. |
|
16087 | 264 |
|
16565 | 265 |
self |
266 |
basicReadEvalPrintLoopWithInput:newInput |
|
267 |
output:outputStream |
|
268 |
error:errorStream |
|
269 |
compiler:compiler |
|
270 |
prompt:false |
|
271 |
print:false. |
|
16087 | 272 |
] ensure:[ |
16565 | 273 |
currentDirectory := savedCurrentDirectory. |
274 |
inputStream := savedInput. |
|
275 |
printFlag := savedPrint. |
|
276 |
prompt := savedPrompt |
|
16087 | 277 |
]. |
278 |
! |
|
279 |
||
10463 | 280 |
cmd_set:lineStream |
10255 | 281 |
self cmd_setOrClear:lineStream to:true |
282 |
||
283 |
"Modified: / 07-12-2006 / 19:04:46 / cg" |
|
284 |
! |
|
285 |
||
10463 | 286 |
cmd_setOrClear:lineStream to:aBoolean |
287 |
|what| |
|
288 |
||
289 |
lineStream skipSeparators. |
|
290 |
what := lineStream nextAlphaNumericWord. |
|
16133 | 291 |
what notNil ifTrue:[ |
20771 | 292 |
(what startsWith:'tra') ifTrue:[ |
293 |
traceFlag := aBoolean. |
|
294 |
^ self. |
|
295 |
]. |
|
296 |
(what startsWith:'tim') ifTrue:[ |
|
297 |
timingFlag := aBoolean. |
|
298 |
^ self. |
|
299 |
]. |
|
300 |
(what startsWith:'pro') ifTrue:[ |
|
301 |
profilingFlag := aBoolean. |
|
302 |
^ self. |
|
303 |
]. |
|
304 |
(what startsWith:'chunk') ifTrue:[ |
|
305 |
doChunkFormat := aBoolean. |
|
306 |
^ self. |
|
307 |
]. |
|
10463 | 308 |
]. |
16133 | 309 |
self errorStream nextPutLine:'? which flag ?'. |
10255 | 310 |
|
10256 | 311 |
"Modified: / 07-12-2006 / 19:13:34 / cg" |
10255 | 312 |
! |
313 |
||
10463 | 314 |
cmd_show:lineStream |
16087 | 315 |
|errStream what all printModule| |
10463 | 316 |
|
13865 | 317 |
" |
318 |
self basicNew cmd_show:'packages' readStream |
|
319 |
" |
|
16087 | 320 |
errStream := self errorStream. |
321 |
||
10463 | 322 |
lineStream skipSeparators. |
323 |
what := lineStream nextAlphaNumericWord. |
|
16133 | 324 |
what notNil ifTrue:[ |
20768 | 325 |
(what startsWith:'var') ifTrue:[ |
326 |
Workspace notNil ifTrue:[ |
|
20770 | 327 |
Workspace workspaceVariables keys asOrderedCollection sort do:[:nm | |
328 |
|holder| |
|
329 |
holder := Workspace workspaceVariables at:nm. |
|
330 |
errStream nextPutAll:nm; nextPutAll:' -> '; nextPutLine:holder value printString. |
|
20768 | 331 |
]. |
332 |
]. |
|
333 |
^ self. |
|
334 |
]. |
|
335 |
(what startsWith:'proc') ifTrue:[ |
|
336 |
MiniDebugger basicNew showProcesses. |
|
337 |
^ self. |
|
338 |
]. |
|
339 |
(what startsWith:'mod') ifTrue:[ |
|
340 |
printModule := |
|
341 |
[:mod | |
|
342 |
errStream |
|
343 |
nextPutAll:' '; |
|
344 |
nextPutAll:(mod package "libraryName"); |
|
345 |
nextPutLine:' (',(mod type),')'. |
|
346 |
]. |
|
13865 | 347 |
|
20768 | 348 |
errStream nextPutLine:'builtIn:'. |
349 |
((ObjectMemory binaryModuleInfo |
|
350 |
reject:[:m | m dynamic]) |
|
351 |
asSortedCollection:[:a :b | a name < b name]) do:printModule. |
|
13865 | 352 |
|
20768 | 353 |
errStream nextPutLine:'dynamic:'. |
354 |
((ObjectMemory binaryModuleInfo |
|
355 |
select:[:m | m dynamic]) |
|
356 |
asSortedCollection:[:a :b | a name < b name]) do:printModule. |
|
13865 | 357 |
|
20768 | 358 |
^ self. |
359 |
]. |
|
360 |
(what startsWith:'mem') ifTrue:[ |
|
361 |
all := ObjectMemory oldSpaceUsed + ObjectMemory symSpaceUsed |
|
362 |
+ ObjectMemory newSpaceUsed. |
|
363 |
errStream |
|
364 |
nextPutLine:('overall: ',(all // 1024) printString,' Kb'); |
|
365 |
nextPutLine:('in use : ',(ObjectMemory bytesUsed // 1024) printString,' Kb'); |
|
366 |
nextPutLine:('free : ',(ObjectMemory freeSpace // 1024) printString,' Kb'); |
|
367 |
nextPutLine:('minorGC: ',(ObjectMemory scavengeCount) printString); |
|
368 |
nextPutLine:('majorGC: ',(ObjectMemory garbageCollectCount) printString). |
|
369 |
^ self. |
|
370 |
]. |
|
371 |
(what startsWith:'flag') ifTrue:[ |
|
372 |
errStream |
|
373 |
nextPutLine:('trace : ',traceFlag printString); |
|
374 |
nextPutLine:('timing: ',timingFlag printString); |
|
375 |
nextPutLine:('chunkFormat: ',doChunkFormat printString). |
|
376 |
^ self. |
|
377 |
]. |
|
10463 | 378 |
]. |
379 |
||
16133 | 380 |
errStream nextPutLine:'? show what ?'. |
10255 | 381 |
|
13866 | 382 |
"Modified: / 07-12-2011 / 22:15:07 / cg" |
10255 | 383 |
! |
384 |
||
10463 | 385 |
cmd_use:lineStream |
16145 | 386 |
|pkg| |
10463 | 387 |
|
388 |
lineStream skipSeparators. |
|
16133 | 389 |
pkg := lineStream upToEnd. |
390 |
pkg isNil ifTrue:[ |
|
16565 | 391 |
'? which package?' errorPrintCR. |
392 |
^ self. |
|
16133 | 393 |
]. |
394 |
pkg := pkg withoutSeparators. |
|
395 |
pkg isEmpty ifTrue:[ |
|
16565 | 396 |
'? which package?' errorPrintCR. |
397 |
^ self. |
|
16133 | 398 |
]. |
399 |
||
16145 | 400 |
[ |
16565 | 401 |
Smalltalk loadPackage:pkg. |
16145 | 402 |
] on:PackageLoadError do:[:ex| |
16565 | 403 |
"/ allow for some shortcuts... |
404 |
(pkg includes:$:) ifTrue:[ |
|
405 |
self errorStream nextPutLine:('Failed to load package: "',pkg,'"'). |
|
406 |
] ifFalse:[ |
|
407 |
"/ try stx standard package |
|
408 |
pkg := 'stx:', pkg. |
|
409 |
ex restart. |
|
410 |
]. |
|
13852 | 411 |
]. |
10255 | 412 |
|
413 |
"Created: / 07-12-2006 / 19:07:56 / cg" |
|
10463 | 414 |
! |
415 |
||
416 |
directive:line |
|
417 |
|s cmd| |
|
418 |
||
419 |
s := line readStream. |
|
420 |
s next. "/ skip the hash |
|
421 |
s skipSeparators. |
|
422 |
||
423 |
cmd := s nextAlphaNumericWord. |
|
16087 | 424 |
cmd notNil ifTrue:[ |
16565 | 425 |
self |
426 |
perform:('cmd_',cmd) asMutator with:s |
|
427 |
ifNotUnderstood:[ |
|
428 |
self errorStream |
|
429 |
nextPutAll:'?? invalid command: '; |
|
430 |
nextPutAll:cmd; |
|
431 |
nextPutAll:'. Type "#help" for help.'; |
|
432 |
cr. |
|
433 |
]. |
|
16087 | 434 |
]. |
10463 | 435 |
|
436 |
"Created: / 07-12-2006 / 18:49:17 / cg" |
|
10255 | 437 |
! ! |
438 |
||
10248 | 439 |
!ReadEvalPrintLoop methodsFor:'evaluation'! |
440 |
||
16565 | 441 |
basicReadEvalPrintLoopWithInput:input output:output error:error |
16087 | 442 |
compiler:compilerClass prompt:prompt print:doPrint |
443 |
||
444 |
"{ Pragma: +optSpace }" |
|
445 |
||
446 |
"the core of the interpreter loop; extracted and parametrized, so it can be called recursive |
|
447 |
for included scripts. |
|
448 |
If chunkFormat is true, chunks are read. |
|
449 |
Otherwise, lines up to an empty line (or EOF) or a line ending in '.' are read. |
|
450 |
A '#' character appearing in the first column of the first line turns off chunkmode." |
|
451 |
||
452 |
[ |
|
20769 | 453 |
|lines chunk| |
16087 | 454 |
|
20769 | 455 |
prompt notNil ifTrue:[ |
456 |
error nextPutAll:prompt. |
|
457 |
]. |
|
16087 | 458 |
|
20769 | 459 |
input atEnd ifTrue:[ |
460 |
error cr. |
|
461 |
^ self. |
|
462 |
]. |
|
16087 | 463 |
|
20769 | 464 |
input peek == $# ifTrue:[ |
465 |
self doChunkFormat:false. |
|
466 |
]. |
|
16087 | 467 |
|
20769 | 468 |
self doChunkFormat ifTrue:[ |
469 |
input skipSeparators. |
|
470 |
chunk := input nextChunk. |
|
471 |
] ifFalse:[ |
|
472 |
lines := OrderedCollection new. |
|
473 |
[ |
|
474 |
|line| |
|
16087 | 475 |
|
20769 | 476 |
line := input nextLine. |
477 |
line notEmptyOrNil ifTrue:[ |
|
478 |
line = '?' ifTrue:[ |
|
479 |
self cmd_help:nil. |
|
480 |
prompt notNil ifTrue:[ |
|
481 |
error nextPutAll:prompt. |
|
482 |
]. |
|
483 |
] ifFalse:[ |
|
484 |
(line startsWith:'#') ifTrue:[ |
|
485 |
self directive:line. |
|
486 |
prompt notNil ifTrue:[ |
|
487 |
error nextPutAll:prompt. |
|
488 |
]. |
|
489 |
] ifFalse:[ |
|
490 |
lines add:line. |
|
491 |
] |
|
492 |
] |
|
493 |
]. |
|
494 |
line notEmptyOrNil and:[(line endsWith:$.) not]. |
|
495 |
] whileTrue. |
|
496 |
chunk := lines asStringWith:Character cr. |
|
497 |
]. |
|
16087 | 498 |
|
20769 | 499 |
(chunk notEmptyOrNil and:[chunk withoutSeparators notEmpty]) ifTrue:[ |
500 |
"abortAll is handled, but not asked for here!!" |
|
501 |
AbortAllOperationRequest handle:[:ex | |
|
502 |
error nextPutLine:('Evaluation aborted: ', ex description) |
|
503 |
] do:[ |
|
504 |
(Error, ControlInterrupt) handle:[:ex | |
|
505 |
prompt isNil ifTrue:[ |
|
506 |
ex reject |
|
507 |
]. |
|
508 |
MiniDebugger enterWithMessage:(ex errorString) mayProceed:true. |
|
509 |
ex mayProceed ifTrue:[ |
|
510 |
ex proceed. |
|
511 |
]. |
|
512 |
error nextPutLine:('Evaluation aborted: ', ex description). |
|
513 |
ex return. |
|
514 |
] do:[ |
|
515 |
|value ms us| |
|
16087 | 516 |
|
20771 | 517 |
profilingFlag == true ifTrue:[ |
518 |
MessageTally spyDetailedOn:[ |
|
519 |
value := (compilerClass new requestor:self) |
|
520 |
evaluate:chunk |
|
521 |
compile:true. |
|
522 |
]. |
|
523 |
doPrint ifTrue:[ |
|
524 |
value printOn:output. output cr. |
|
525 |
]. |
|
526 |
] ifFalse:[ |
|
527 |
us := Time microsecondsToRun:[ |
|
528 |
value := (compilerClass new requestor:self) |
|
529 |
evaluate:chunk compile:true. |
|
530 |
]. |
|
531 |
doPrint ifTrue:[ |
|
532 |
value printOn:output. output cr. |
|
533 |
]. |
|
16087 | 534 |
|
20771 | 535 |
timingFlag == true ifTrue:[ |
536 |
'execution time: ' printOn:error. |
|
537 |
us < 1000 ifTrue:[ |
|
538 |
us < 1 ifTrue:[ |
|
539 |
'too small to measure (<1us)' printOn:error. |
|
540 |
] ifFalse:[ |
|
541 |
us printOn:output. 'us' printOn:error. |
|
542 |
] |
|
20769 | 543 |
] ifFalse:[ |
20771 | 544 |
((us / 1000) asFixedPoint:2) printOn:output. 'ms' printOn:error. |
545 |
]. |
|
546 |
error cr. |
|
20769 | 547 |
]. |
548 |
]. |
|
549 |
Workspace notNil ifTrue:[ |
|
550 |
Workspace rememberResultAsWorkspaceVariable:value. |
|
551 |
]. |
|
552 |
]. |
|
553 |
]. |
|
554 |
]. |
|
16087 | 555 |
] loop. |
556 |
||
557 |
" |
|
558 |
(ReadEvalPrintLoop new prompt:'>') readEvalPrintLoop |
|
559 |
" |
|
560 |
||
561 |
"Created: / 07-12-2006 / 17:27:21 / cg" |
|
562 |
"Modified: / 06-12-2011 / 15:29:03 / cg" |
|
563 |
! |
|
564 |
||
10463 | 565 |
readEvalPrintLoop |
566 |
"{ Pragma: +optSpace }" |
|
567 |
||
568 |
"simple read-eval-print loop for non-graphical Minitalk. |
|
569 |
If the chunkFormat-argument is true, chunks are read. |
|
16087 | 570 |
Otherwise, lines up to an empty line (or EOF) are read. |
571 |
A '#' character appearing in the first column of the first line |
|
572 |
switches to chunkmode." |
|
10463 | 573 |
|
10628
284266d54dbe
#exit only leaves the rep-loop
Claus Gittinger <cg@exept.de>
parents:
10500
diff
changeset
|
574 |
exitAction := [^ self]. |
284266d54dbe
#exit only leaves the rep-loop
Claus Gittinger <cg@exept.de>
parents:
10500
diff
changeset
|
575 |
|
10463 | 576 |
ControlInterrupt handle:[:ex | |
16565 | 577 |
self errorStream nextPutLine:('Caught: ', ex description). |
578 |
ex restart. |
|
10463 | 579 |
] do:[ |
16565 | 580 |
|input output error compilerClass| |
10463 | 581 |
|
16565 | 582 |
"/ re-evaluate these in the loop, so they can be changed dynamically |
583 |
input := self inputStream. |
|
584 |
output := self outputStream. |
|
585 |
error := self errorStream. |
|
10463 | 586 |
|
16565 | 587 |
compilerClass := compiler ? Compiler ? Parser. |
588 |
compilerClass isNil ifTrue:[ |
|
589 |
self errorStream nextPutLine:('oops - no Compiler class found'). |
|
590 |
^ self. |
|
591 |
]. |
|
592 |
self |
|
593 |
basicReadEvalPrintLoopWithInput:input output:output error:error |
|
594 |
compiler:compilerClass prompt:prompt print:(printFlag ? true). |
|
10463 | 595 |
] |
596 |
||
597 |
" |
|
598 |
(ReadEvalPrintLoop new prompt:'>') readEvalPrintLoop |
|
599 |
" |
|
600 |
||
601 |
"Created: / 07-12-2006 / 17:27:21 / cg" |
|
13859
81451e09af8d
changed: #readEvalPrintLoop
Claus Gittinger <cg@exept.de>
parents:
13858
diff
changeset
|
602 |
"Modified: / 06-12-2011 / 15:29:03 / cg" |
10248 | 603 |
! ! |
604 |
||
16089 | 605 |
!ReadEvalPrintLoop methodsFor:'queries'! |
606 |
||
607 |
autoDefineVariables |
|
608 |
"when evaluating with --eval, auto define any variables" |
|
609 |
||
610 |
^ #workspace |
|
611 |
! ! |
|
612 |
||
10248 | 613 |
!ReadEvalPrintLoop class methodsFor:'documentation'! |
614 |
||
615 |
version |
|
19379 | 616 |
^ '$Header$' |
13121
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
617 |
! |
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
618 |
|
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
619 |
version_CVS |
19379 | 620 |
^ '$Header$' |
10248 | 621 |
! ! |
19379 | 622 |