author | Claus Gittinger <cg@exept.de> |
Sat, 22 Feb 2014 17:34:26 +0100 | |
changeset 16113 | 411bfb1ec52c |
parent 16089 | 04545ee7ab04 |
child 16115 | 032fc08ead9b |
permissions | -rw-r--r-- |
10249 | 1 |
" |
2 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
10248 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
14 |
Object subclass:#ReadEvalPrintLoop |
|
10254 | 15 |
instanceVariableNames:'inputStream outputStream errorStream compiler prompt |
16087 | 16 |
doChunkFormat traceFlag timingFlag printFlag exitAction |
17 |
currentDirectory' |
|
10248 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
10277 | 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 |
|
28 |
All Rights Reserved |
|
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: |
284266d54dbe
#exit only leaves the rep-loop
Claus Gittinger <cg@exept.de>
parents:
10500
diff
changeset
|
46 |
#exit - exit the rep-loop |
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: |
49 |
1) traditional chunk format (bang-separated chunks, bangs duplicated) |
|
50 |
this is the traditional fileIn format, as generated by fileOut from the browser |
|
51 |
||
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. |
|
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 |
|
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 |
16087 | 202 |
stx:libwidg .............. GUI package |
203 |
stx:libtool .............. IDE tool package |
|
204 |
stx:goodies/regex ........ regex package |
|
205 |
stx:goodies/petitparser .. peg parser package |
|
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 |
10463 | 208 |
variables .......... interpreter variables |
209 |
processes .......... processes |
|
210 |
memory ............. memory usage |
|
211 |
flags .............. flags |
|
13866 | 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 |
10463 | 214 |
trace .............. tracing execution |
215 |
timing ............. timing execution |
|
16084 | 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. |
|
229 |
||
230 |
filename := filename asFilename. |
|
231 |
filename isAbsolute ifFalse:[ |
|
232 |
filename := currentDirectory construct:filename. |
|
233 |
]. |
|
234 |
||
235 |
newInput := filename readStream. |
|
236 |
newInput isNil ifTrue:[ |
|
237 |
('Could not find file: "',filename,'"') errorPrintCR. |
|
238 |
^ self. |
|
239 |
]. |
|
240 |
||
241 |
[ |
|
242 |
savedCurrentDirectory := currentDirectory. |
|
243 |
savedInput := inputStream. |
|
244 |
savedPrint := printFlag. |
|
245 |
savedPrompt := prompt. |
|
246 |
||
247 |
currentDirectory := filename directory. |
|
248 |
inputStream := newInput. |
|
249 |
||
250 |
self |
|
251 |
basicReadEvalPrintLoopWithInput:newInput |
|
252 |
output:outputStream |
|
253 |
error:errorStream |
|
254 |
compiler:compiler |
|
255 |
prompt:false |
|
256 |
print:false. |
|
257 |
] ensure:[ |
|
258 |
currentDirectory := savedCurrentDirectory. |
|
259 |
inputStream := savedInput. |
|
260 |
printFlag := savedPrint. |
|
261 |
prompt := savedPrompt |
|
262 |
]. |
|
263 |
! |
|
264 |
||
10463 | 265 |
cmd_set:lineStream |
10255 | 266 |
self cmd_setOrClear:lineStream to:true |
267 |
||
268 |
"Modified: / 07-12-2006 / 19:04:46 / cg" |
|
269 |
! |
|
270 |
||
10463 | 271 |
cmd_setOrClear:lineStream to:aBoolean |
272 |
|what| |
|
273 |
||
274 |
lineStream skipSeparators. |
|
275 |
what := lineStream nextAlphaNumericWord. |
|
276 |
(what startsWith:'tra') ifTrue:[ |
|
277 |
traceFlag := aBoolean. |
|
278 |
^ self. |
|
279 |
]. |
|
280 |
(what startsWith:'tim') ifTrue:[ |
|
281 |
timingFlag := aBoolean. |
|
282 |
^ self. |
|
283 |
]. |
|
16084 | 284 |
(what startsWith:'chunk') ifTrue:[ |
285 |
doChunkFormat := aBoolean. |
|
286 |
^ self. |
|
287 |
]. |
|
10463 | 288 |
|
289 |
self errorStream nextPutLine:'?? which flag ?'. |
|
10255 | 290 |
|
10256 | 291 |
"Modified: / 07-12-2006 / 19:13:34 / cg" |
10255 | 292 |
! |
293 |
||
10463 | 294 |
cmd_show:lineStream |
16087 | 295 |
|errStream what all printModule| |
10463 | 296 |
|
13865 | 297 |
" |
298 |
self basicNew cmd_show:'packages' readStream |
|
299 |
" |
|
16087 | 300 |
errStream := self errorStream. |
301 |
||
10463 | 302 |
lineStream skipSeparators. |
303 |
what := lineStream nextAlphaNumericWord. |
|
304 |
(what startsWith:'var') ifTrue:[ |
|
16088 | 305 |
Workspace workspaceVariables keysAndValuesDo:[:nm :h | |
306 |
errStream nextPutAll:nm; nextPutAll:' -> '; nextPutLine:h value. |
|
307 |
]. |
|
10463 | 308 |
^ self. |
309 |
]. |
|
310 |
(what startsWith:'proc') ifTrue:[ |
|
311 |
MiniDebugger basicNew showProcesses. |
|
312 |
^ self. |
|
313 |
]. |
|
13866 | 314 |
(what startsWith:'mod') ifTrue:[ |
13865 | 315 |
printModule := |
316 |
[:mod | |
|
16087 | 317 |
errStream |
13865 | 318 |
nextPutAll:' '; |
319 |
nextPutAll:(mod package "libraryName"); |
|
320 |
nextPutLine:' (',(mod type),')'. |
|
321 |
]. |
|
322 |
||
16087 | 323 |
errStream nextPutLine:'builtIn:'. |
13865 | 324 |
((ObjectMemory binaryModuleInfo |
15365 | 325 |
reject:[:m | m dynamic]) |
13865 | 326 |
asSortedCollection:[:a :b | a name < b name]) do:printModule. |
327 |
||
16087 | 328 |
errStream nextPutLine:'dynamic:'. |
13865 | 329 |
((ObjectMemory binaryModuleInfo |
330 |
select:[:m | m dynamic]) |
|
331 |
asSortedCollection:[:a :b | a name < b name]) do:printModule. |
|
332 |
||
333 |
^ self. |
|
334 |
]. |
|
10463 | 335 |
(what startsWith:'mem') ifTrue:[ |
13865 | 336 |
all := ObjectMemory oldSpaceUsed + ObjectMemory symSpaceUsed |
337 |
+ ObjectMemory newSpaceUsed. |
|
16087 | 338 |
errStream |
13865 | 339 |
nextPutLine:('overall: ',(all // 1024) printString,' Kb'); |
340 |
nextPutLine:('in use : ',(ObjectMemory bytesUsed // 1024) printString,' Kb'); |
|
10463 | 341 |
nextPutLine:('free : ',(ObjectMemory freeSpace // 1024) printString,' Kb'); |
342 |
nextPutLine:('minorGC: ',(ObjectMemory scavengeCount) printString); |
|
343 |
nextPutLine:('majorGC: ',(ObjectMemory garbageCollectCount) printString). |
|
344 |
^ self. |
|
345 |
]. |
|
346 |
(what startsWith:'flag') ifTrue:[ |
|
16087 | 347 |
errStream |
16084 | 348 |
nextPutLine:('trace : ',traceFlag printString); |
349 |
nextPutLine:('timing: ',timingFlag printString); |
|
350 |
nextPutLine:('chunkFormat: ',doChunkFormat printString). |
|
10463 | 351 |
^ self. |
352 |
]. |
|
353 |
||
16087 | 354 |
errStream nextPutLine:'?? show what ?'. |
10255 | 355 |
|
13866 | 356 |
"Modified: / 07-12-2011 / 22:15:07 / cg" |
10255 | 357 |
! |
358 |
||
10463 | 359 |
cmd_use:lineStream |
13852 | 360 |
|pkg ok| |
10463 | 361 |
|
362 |
lineStream skipSeparators. |
|
363 |
pkg := lineStream upToEnd withoutSeparators. |
|
13852 | 364 |
(ok := Smalltalk loadPackage:pkg) ifFalse:[ |
365 |
"/ allow for some shortcuts... |
|
366 |
(pkg includes:$:) ifFalse:[ |
|
367 |
"/ try stx standard package |
|
13858 | 368 |
ok := Smalltalk loadPackage:('stx:',pkg) |
13852 | 369 |
]. |
370 |
]. |
|
371 |
ok ifFalse:[ |
|
16087 | 372 |
self errorStream nextPutLine:('Failed to load package: "',pkg,'"'). |
13852 | 373 |
]. |
10255 | 374 |
|
375 |
"Created: / 07-12-2006 / 19:07:56 / cg" |
|
10463 | 376 |
! |
377 |
||
378 |
directive:line |
|
379 |
|s cmd| |
|
380 |
||
381 |
s := line readStream. |
|
382 |
s next. "/ skip the hash |
|
383 |
s skipSeparators. |
|
384 |
||
385 |
cmd := s nextAlphaNumericWord. |
|
16087 | 386 |
cmd notNil ifTrue:[ |
387 |
self |
|
388 |
perform:('cmd_',cmd,':') asSymbol with:s |
|
389 |
ifNotUnderstood:[ |
|
390 |
self errorStream |
|
391 |
nextPutAll:'?? invalid command: '; |
|
392 |
nextPutAll:cmd; |
|
393 |
nextPutAll:'. Type "#help" for help.'; |
|
394 |
cr. |
|
395 |
]. |
|
396 |
]. |
|
10463 | 397 |
|
398 |
"Created: / 07-12-2006 / 18:49:17 / cg" |
|
10255 | 399 |
! ! |
400 |
||
10248 | 401 |
!ReadEvalPrintLoop methodsFor:'evaluation'! |
402 |
||
16087 | 403 |
basicReadEvalPrintLoopWithInput:input output:output error:error |
404 |
compiler:compilerClass prompt:prompt print:doPrint |
|
405 |
||
406 |
"{ Pragma: +optSpace }" |
|
407 |
||
408 |
"the core of the interpreter loop; extracted and parametrized, so it can be called recursive |
|
409 |
for included scripts. |
|
410 |
If chunkFormat is true, chunks are read. |
|
411 |
Otherwise, lines up to an empty line (or EOF) or a line ending in '.' are read. |
|
412 |
A '#' character appearing in the first column of the first line turns off chunkmode." |
|
413 |
||
414 |
[ |
|
415 |
|lines chunk| |
|
416 |
||
417 |
prompt notNil ifTrue:[ |
|
418 |
error nextPutAll:prompt. |
|
419 |
]. |
|
420 |
||
421 |
input atEnd ifTrue:[ |
|
422 |
^ self. |
|
423 |
]. |
|
424 |
||
425 |
input peek == $# ifTrue:[ |
|
426 |
self doChunkFormat:false. |
|
427 |
]. |
|
428 |
||
429 |
self doChunkFormat ifTrue:[ |
|
430 |
input skipSeparators. |
|
431 |
chunk := input nextChunk. |
|
432 |
] ifFalse:[ |
|
433 |
lines := OrderedCollection new. |
|
434 |
[ |
|
435 |
|line| |
|
436 |
||
437 |
line := input nextLine. |
|
438 |
line notEmptyOrNil ifTrue:[ |
|
439 |
line = '?' ifTrue:[ |
|
440 |
self cmd_help:nil. |
|
441 |
prompt notNil ifTrue:[ |
|
442 |
error nextPutAll:prompt. |
|
443 |
]. |
|
444 |
] ifFalse:[ |
|
445 |
(line startsWith:'#') ifTrue:[ |
|
446 |
self directive:line. |
|
447 |
prompt notNil ifTrue:[ |
|
448 |
error nextPutAll:prompt. |
|
449 |
]. |
|
450 |
] ifFalse:[ |
|
451 |
lines add:line. |
|
452 |
] |
|
453 |
] |
|
454 |
]. |
|
455 |
line notEmptyOrNil and:[(line endsWith:$.) not]. |
|
456 |
] whileTrue. |
|
457 |
chunk := lines asStringWith:Character cr. |
|
458 |
]. |
|
459 |
||
460 |
chunk notEmptyOrNil ifTrue:[ |
|
461 |
"abortAll is handled, but not asked for here!!" |
|
462 |
AbortAllOperationRequest handle:[:ex | |
|
463 |
error nextPutLine:('Evaluation aborted: ', ex description) |
|
464 |
] do:[ |
|
465 |
(Error, ControlInterrupt) handle:[:ex | |
|
466 |
prompt isNil ifTrue:[ |
|
467 |
ex reject |
|
468 |
]. |
|
469 |
MiniDebugger enterWithMessage:(ex errorString) mayProceed:true. |
|
470 |
ex mayProceed ifTrue:[ |
|
471 |
ex proceed. |
|
472 |
]. |
|
473 |
error nextPutLine:('Evaluation aborted: ', ex description). |
|
474 |
ex return. |
|
475 |
] do:[ |
|
476 |
|value ms us| |
|
477 |
||
478 |
ms := Time millisecondsToRun:[ |
|
479 |
us := Time microsecondsToRun:[ |
|
16089 | 480 |
value := (compilerClass new |
481 |
requestor:self) |
|
482 |
evaluate:chunk |
|
483 |
compile:true. |
|
16087 | 484 |
]. |
485 |
]. |
|
486 |
doPrint ifTrue:[ |
|
487 |
value printOn:output. output cr. |
|
488 |
]. |
|
489 |
||
490 |
timingFlag == true ifTrue:[ |
|
491 |
'execution time: ' printOn:error. |
|
492 |
ms < 1 ifTrue:[ |
|
493 |
us < 1 ifTrue:[ |
|
494 |
'too small to measure (<1us)' printOn:error. |
|
495 |
] ifFalse:[ |
|
496 |
us printOn:output. 'us' printOn:error. |
|
497 |
] |
|
498 |
] ifFalse:[ |
|
499 |
ms printOn:output. 'ms' printOn:error. |
|
500 |
]. |
|
501 |
error cr. |
|
502 |
]. |
|
503 |
]. |
|
504 |
]. |
|
505 |
]. |
|
506 |
] loop. |
|
507 |
||
508 |
" |
|
509 |
(ReadEvalPrintLoop new prompt:'>') readEvalPrintLoop |
|
510 |
" |
|
511 |
||
512 |
"Created: / 07-12-2006 / 17:27:21 / cg" |
|
513 |
"Modified: / 06-12-2011 / 15:29:03 / cg" |
|
514 |
! |
|
515 |
||
10463 | 516 |
readEvalPrintLoop |
517 |
"{ Pragma: +optSpace }" |
|
518 |
||
519 |
"simple read-eval-print loop for non-graphical Minitalk. |
|
520 |
If the chunkFormat-argument is true, chunks are read. |
|
16087 | 521 |
Otherwise, lines up to an empty line (or EOF) are read. |
522 |
A '#' character appearing in the first column of the first line |
|
523 |
switches to chunkmode." |
|
10463 | 524 |
|
10628
284266d54dbe
#exit only leaves the rep-loop
Claus Gittinger <cg@exept.de>
parents:
10500
diff
changeset
|
525 |
exitAction := [^ self]. |
284266d54dbe
#exit only leaves the rep-loop
Claus Gittinger <cg@exept.de>
parents:
10500
diff
changeset
|
526 |
|
10463 | 527 |
ControlInterrupt handle:[:ex | |
528 |
self errorStream nextPutLine:('Cought: ', ex description). |
|
529 |
ex restart. |
|
530 |
] do:[ |
|
16087 | 531 |
|input output error compilerClass| |
10463 | 532 |
|
16087 | 533 |
"/ re-evaluate these in the loop, so they can be changed dynamically |
534 |
input := self inputStream. |
|
535 |
output := self outputStream. |
|
536 |
error := self errorStream. |
|
10463 | 537 |
|
16087 | 538 |
compilerClass := compiler ? Compiler ? Parser. |
539 |
compilerClass isNil ifTrue:[ |
|
540 |
self errorStream nextPutLine:('oops - no Compiler class found'). |
|
541 |
^ self. |
|
542 |
]. |
|
543 |
self |
|
544 |
basicReadEvalPrintLoopWithInput:input output:output error:error |
|
545 |
compiler:compilerClass prompt:prompt print:(printFlag ? true). |
|
10463 | 546 |
] |
547 |
||
548 |
" |
|
549 |
(ReadEvalPrintLoop new prompt:'>') readEvalPrintLoop |
|
550 |
" |
|
551 |
||
552 |
"Created: / 07-12-2006 / 17:27:21 / cg" |
|
13859
81451e09af8d
changed: #readEvalPrintLoop
Claus Gittinger <cg@exept.de>
parents:
13858
diff
changeset
|
553 |
"Modified: / 06-12-2011 / 15:29:03 / cg" |
10248 | 554 |
! ! |
555 |
||
16089 | 556 |
!ReadEvalPrintLoop methodsFor:'queries'! |
557 |
||
558 |
autoDefineVariables |
|
559 |
"when evaluating with --eval, auto define any variables" |
|
560 |
||
561 |
^ #workspace |
|
562 |
! ! |
|
563 |
||
10248 | 564 |
!ReadEvalPrintLoop class methodsFor:'documentation'! |
565 |
||
566 |
version |
|
16089 | 567 |
^ '$Header: /cvs/stx/stx/libbasic/ReadEvalPrintLoop.st,v 1.46 2014-02-20 08:43:50 cg Exp $' |
13121
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
568 |
! |
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
569 |
|
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
570 |
version_CVS |
16089 | 571 |
^ '$Header: /cvs/stx/stx/libbasic/ReadEvalPrintLoop.st,v 1.46 2014-02-20 08:43:50 cg Exp $' |
10248 | 572 |
! ! |
15365 | 573 |