author | Claus Gittinger <cg@exept.de> |
Thu, 27 Jun 2019 15:21:18 +0200 | |
changeset 24377 | 2fbcb2fa6c43 |
parent 24106 | 57fa3fced677 |
child 25283 | b6acb2c8a574 |
permissions | -rw-r--r-- |
22574 | 1 |
"{ Encoding: utf8 }" |
2 |
||
10249 | 3 |
" |
4 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
16565 | 5 |
All Rights Reserved |
10249 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
10248 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
19379 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
10248 | 18 |
Object subclass:#ReadEvalPrintLoop |
22764 | 19 |
instanceVariableNames:'stdin stdout stderr inputStream outputStream errorStream compiler |
20 |
prompt doChunkFormat traceFlag timingFlag profilingFlag printFlag |
|
20935 | 21 |
exitAction currentDirectory lastEditedClass lastEditedSelector |
22746 | 22 |
editorCommand confirmDebugger noDebugger debuggerUsed |
22765 | 23 |
returnValuePrinting returnValuePrompt defaultPackagePrefix |
24 |
answerPrompt' |
|
16228 | 25 |
classVariableNames:'' |
26 |
poolDictionaries:'' |
|
27 |
category:'System-Support' |
|
10248 | 28 |
! |
29 |
||
10249 | 30 |
!ReadEvalPrintLoop class methodsFor:'documentation'! |
31 |
||
32 |
copyright |
|
33 |
" |
|
34 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
16565 | 35 |
All Rights Reserved |
10249 | 36 |
|
37 |
This software is furnished under a license and may be used |
|
38 |
only in accordance with the terms of that license and with the |
|
39 |
inclusion of the above copyright notice. This software may not |
|
40 |
be provided or otherwise made available to, or used by, any |
|
41 |
other person. No title to or ownership of the software is |
|
42 |
hereby transferred. |
|
43 |
" |
|
10461
0b2935207fec
+correctableError:position:to:
Claus Gittinger <cg@exept.de>
parents:
10277
diff
changeset
|
44 |
! |
0b2935207fec
+correctableError:position:to:
Claus Gittinger <cg@exept.de>
parents:
10277
diff
changeset
|
45 |
|
0b2935207fec
+correctableError:position:to:
Claus Gittinger <cg@exept.de>
parents:
10277
diff
changeset
|
46 |
documentation |
0b2935207fec
+correctableError:position:to:
Claus Gittinger <cg@exept.de>
parents:
10277
diff
changeset
|
47 |
" |
0b2935207fec
+correctableError:position:to:
Claus Gittinger <cg@exept.de>
parents:
10277
diff
changeset
|
48 |
A simple read-eval-print loop for non-GUI or stscript operation. |
22735 | 49 |
Invoked, for example if stx is started with a --repl argument, |
50 |
or by the MiniDebugger with the 'I' command. |
|
20833 | 51 |
|
10628
284266d54dbe
#exit only leaves the rep-loop
Claus Gittinger <cg@exept.de>
parents:
10500
diff
changeset
|
52 |
A line starting with '?' shows the usage message. |
284266d54dbe
#exit only leaves the rep-loop
Claus Gittinger <cg@exept.de>
parents:
10500
diff
changeset
|
53 |
Lines starting with '#' are directives: |
22576 | 54 |
#exit - exit the rep-loop |
55 |
#show ... - show various infos |
|
56 |
#use package - show various infos |
|
20833 | 57 |
type '?' to see more. |
58 |
||
16087 | 59 |
The input can be in one of two formats: |
20833 | 60 |
1) traditional chunk format (bang-separated chunks, bangs duplicated) |
61 |
this is the traditional fileIn format, as generated by fileOut from the browser |
|
16087 | 62 |
|
20833 | 63 |
2) interactive line mode. Chunks are any number of lines up to either an empty line or |
64 |
a line ending in a period. This is more useful for an interactive REPL, where statements/expressions |
|
65 |
are entered linewise by a user. |
|
16087 | 66 |
|
67 |
The input can is switched to non-chunk format whenever a line with a '#' in the first column appears. |
|
20833 | 68 |
|
20933 | 69 |
Try it (but only if you have a console): |
70 |
Smalltalk readEvalPrintLoop |
|
71 |
||
20833 | 72 |
[Author:] |
73 |
Claus Gittinger |
|
10461
0b2935207fec
+correctableError:position:to:
Claus Gittinger <cg@exept.de>
parents:
10277
diff
changeset
|
74 |
" |
10249 | 75 |
! ! |
10248 | 76 |
|
77 |
!ReadEvalPrintLoop methodsFor:'accessing'! |
|
78 |
||
22765 | 79 |
answerPrompt |
80 |
"the string shown before the answer" |
|
81 |
||
82 |
^ answerPrompt ? '-> (Answer): ' |
|
83 |
! |
|
84 |
||
85 |
answerPrompt:aString |
|
86 |
"set the string shown before the answer" |
|
87 |
||
88 |
answerPrompt := aString. |
|
89 |
! |
|
90 |
||
10463 | 91 |
compiler:something |
22765 | 92 |
"assign a compiler to use; |
93 |
can be used to change the language" |
|
16087 | 94 |
|
10463 | 95 |
compiler := something. |
10248 | 96 |
! |
97 |
||
22735 | 98 |
confirmDebugger |
99 |
"true if the user is asked for a debugger in case of errors" |
|
100 |
||
101 |
^ confirmDebugger ? true |
|
102 |
! |
|
103 |
||
104 |
confirmDebugger:aBoolean |
|
105 |
"true if the user is asked for a debugger in case of errors" |
|
106 |
||
107 |
confirmDebugger := aBoolean |
|
108 |
! |
|
109 |
||
110 |
debuggerUsed |
|
111 |
"by default, the miniDebugger is given control in case of an error; |
|
112 |
you may want to write (subclass) your own ;-)" |
|
113 |
||
114 |
^ debuggerUsed ? MiniDebugger |
|
115 |
! |
|
116 |
||
117 |
debuggerUsed:aDebuggerClass |
|
118 |
"by default, the miniDebugger is given control in case of an error; |
|
119 |
you may want to write (subclass) your own ;-)" |
|
120 |
||
121 |
debuggerUsed := aDebuggerClass |
|
122 |
! |
|
123 |
||
22765 | 124 |
defaultPackagePrefix |
125 |
"a default to be prepended to #use packages" |
|
126 |
||
127 |
^ defaultPackagePrefix ? 'stx:' |
|
128 |
! |
|
129 |
||
130 |
defaultPackagePrefix:aStringOrNil |
|
131 |
"a default to be prepended to #use packages" |
|
132 |
||
133 |
defaultPackagePrefix := aStringOrNil |
|
134 |
! |
|
135 |
||
10632 | 136 |
doChunkFormat |
16087 | 137 |
"true if currently reading chunk format" |
138 |
||
10632 | 139 |
^ doChunkFormat ? true |
140 |
||
141 |
"Created: / 07-12-2006 / 18:24:04 / cg" |
|
142 |
! |
|
143 |
||
16087 | 144 |
doChunkFormat:aBoolean |
145 |
"enable/disable chunk format" |
|
146 |
||
147 |
doChunkFormat := aBoolean. |
|
10254 | 148 |
|
149 |
"Created: / 07-12-2006 / 18:24:04 / cg" |
|
10248 | 150 |
! |
151 |
||
20935 | 152 |
editorCommand |
21934 | 153 |
"the editor command to use with the #edit directive. |
154 |
Uses the STX_EDITOR or EDITOR shell variables' value, if defined; |
|
155 |
if not, the value in the classvar EDITORCOMMAND if non-nil; |
|
156 |
otheriwse vi (notepad on windows)" |
|
157 |
||
20935 | 158 |
|editor| |
159 |
||
160 |
(editor := editorCommand) isNil ifTrue:[ |
|
161 |
editor := OperatingSystem getEnvironment:'STX_EDITOR'. |
|
162 |
editor isNil ifTrue:[ |
|
163 |
editor := OperatingSystem getEnvironment:'EDITOR'. |
|
164 |
editor isNil ifTrue:[ |
|
165 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
|
166 |
editor := 'notepad'. |
|
167 |
] ifFalse:[ |
|
168 |
editor := 'vi'. |
|
169 |
]. |
|
170 |
]. |
|
171 |
]. |
|
172 |
]. |
|
173 |
^ editor |
|
174 |
||
175 |
"Created: / 08-11-2016 / 22:45:22 / cg" |
|
21934 | 176 |
"Modified: / 24-06-2017 / 09:54:10 / cg" |
20935 | 177 |
! |
178 |
||
10463 | 179 |
errorStream |
16087 | 180 |
"return the current error stream" |
181 |
||
19379 | 182 |
errorStream notNil ifTrue:[^ errorStream]. |
183 |
^ Processor activeProcess stderr |
|
10256 | 184 |
|
19379 | 185 |
"Created: / 07-12-2006 / 19:12:27 / cg" |
10256 | 186 |
! |
187 |
||
22832 | 188 |
errorStream:aStream |
189 |
"assign an error stream" |
|
190 |
||
191 |
errorStream := stderr := aStream. |
|
192 |
||
193 |
"Created: / 07-12-2006 / 17:33:39 / cg" |
|
194 |
! |
|
195 |
||
16087 | 196 |
input:aStream |
22832 | 197 |
<resource: #obsolete> |
16087 | 198 |
"assign an input stream" |
199 |
||
22775 | 200 |
inputStream := stdin := aStream asLineNumberReadStream. |
10248 | 201 |
|
202 |
"Modified: / 07-12-2006 / 17:33:31 / cg" |
|
203 |
! |
|
204 |
||
10463 | 205 |
inputStream |
16087 | 206 |
"get the current input stream" |
207 |
||
19379 | 208 |
inputStream notNil ifTrue:[^ inputStream]. |
209 |
^ Processor activeProcess stdin |
|
10463 | 210 |
|
211 |
"Created: / 07-12-2006 / 19:12:13 / cg" |
|
10256 | 212 |
! |
213 |
||
22832 | 214 |
inputStream:aStream |
215 |
"assign an input stream" |
|
216 |
||
217 |
inputStream := stdin := aStream asLineNumberReadStream. |
|
218 |
||
219 |
"Modified: / 07-12-2006 / 17:33:31 / cg" |
|
220 |
! |
|
221 |
||
22746 | 222 |
noDebugger |
223 |
"true if no debugger should be activated on errors (aborts)" |
|
224 |
||
225 |
^ noDebugger ? false |
|
226 |
! |
|
227 |
||
228 |
noDebugger:aBoolean |
|
229 |
"true if no debugger should be activated on errors (aborts)" |
|
230 |
||
231 |
noDebugger := aBoolean |
|
232 |
! |
|
233 |
||
16087 | 234 |
output:aStream |
22832 | 235 |
<resource: #obsolete> |
16087 | 236 |
"assign an output stream" |
237 |
||
22775 | 238 |
outputStream := stdout := aStream. |
10248 | 239 |
|
240 |
"Created: / 07-12-2006 / 17:27:48 / cg" |
|
241 |
! |
|
242 |
||
10463 | 243 |
outputStream |
19379 | 244 |
"return the current output stream" |
16087 | 245 |
|
19379 | 246 |
outputStream notNil ifTrue:[^ outputStream]. |
247 |
^ Processor activeProcess stdout |
|
10463 | 248 |
|
249 |
"Created: / 07-12-2006 / 19:12:27 / cg" |
|
250 |
! |
|
251 |
||
22832 | 252 |
outputStream:aStream |
253 |
"assign an output stream" |
|
254 |
||
255 |
outputStream := stdout := aStream. |
|
256 |
||
257 |
"Created: / 07-12-2006 / 17:27:48 / cg" |
|
258 |
! |
|
259 |
||
22743 | 260 |
printFlag |
261 |
"true if the return value of expressions should be printed" |
|
262 |
||
263 |
^ printFlag ? true |
|
264 |
! |
|
265 |
||
266 |
printFlag:aBoolean |
|
267 |
"true if the return value of expressions should be printed" |
|
268 |
||
269 |
printFlag := aBoolean |
|
270 |
! |
|
271 |
||
16087 | 272 |
prompt:aString |
22765 | 273 |
"set the string shown as prompt" |
16087 | 274 |
|
275 |
prompt := aString. |
|
10248 | 276 |
! ! |
277 |
||
10631 | 278 |
!ReadEvalPrintLoop methodsFor:'compiler interface-error handling'! |
279 |
||
280 |
correctableError:message position:pos1 to:pos2 from:aCompiler |
|
281 |
"compiler notifies us of an error - ignore it" |
|
282 |
||
15702 | 283 |
^ false "/ no correction |
10631 | 284 |
! |
285 |
||
286 |
correctableSelectorWarning:aString position:relPos to:relEndPos from:aCompiler |
|
287 |
"compiler notifies us of a warning - ignore it" |
|
288 |
||
289 |
^ false |
|
290 |
! |
|
291 |
||
13121
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
292 |
correctableWarning:message position:pos1 to:pos2 from:aCompiler |
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
293 |
"compiler notifies us of an error - ignore it" |
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
294 |
|
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
295 |
^ false |
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
296 |
|
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
297 |
"Created: / 02-11-2010 / 13:29:22 / cg" |
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
298 |
! |
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
299 |
|
10631 | 300 |
error:aString position:relPos to:relEndPos from:aCompiler |
301 |
"compiler notifies us of a warning - ignore it" |
|
302 |
||
22761 | 303 |
self error:('Syntax Error: ',aString). |
10631 | 304 |
! |
305 |
||
306 |
unusedVariableWarning:aString position:relPos to:relEndPos from:aCompiler |
|
307 |
"compiler notifies us of a warning - ignore it" |
|
308 |
||
309 |
^ false |
|
310 |
! |
|
311 |
||
312 |
warning:aString position:relPos to:relEndPos from:aCompiler |
|
313 |
"compiler notifies us of a warning - ignore it" |
|
314 |
||
315 |
^ self |
|
316 |
! ! |
|
317 |
||
10255 | 318 |
!ReadEvalPrintLoop methodsFor:'directives'! |
319 |
||
22735 | 320 |
askYesNo:message |
22771 | 321 |
stderr show:message. |
22735 | 322 |
^ (self inputStream nextLine withoutSeparators startsWith:'y'). |
323 |
! |
|
324 |
||
325 |
cmd_apropos:lineStream |
|
326 |
"apropos directive; i.e. |
|
327 |
#apropos collection [;more] |
|
328 |
" |
|
329 |
||
330 |
|words classNamesMatching selectorsMatching showList| |
|
331 |
||
332 |
lineStream skipSeparators. |
|
333 |
words := lineStream upToEnd asCollectionOfSubstringsSeparatedBy:$;. |
|
334 |
words := words select:[:each | each notEmpty]. |
|
335 |
words := words select:[:each | each isBlank not]. |
|
336 |
||
337 |
(words isEmpty) ifTrue:[ |
|
22771 | 338 |
stderr showCR:'? usage: #apropos <word> [; morewords]'. |
22735 | 339 |
^ self. |
340 |
]. |
|
341 |
||
342 |
"/ search in classes: |
|
343 |
classNamesMatching := Smalltalk allClasses |
|
344 |
select:[:cls | |
|
345 |
cls isPrivate not |
|
346 |
and:[ words conform:[:word | |
|
347 |
cls name matches:word caseSensitive:false]]] |
|
348 |
thenCollect:#name. |
|
349 |
"/ search in method names: |
|
350 |
selectorsMatching := (Smalltalk allClasses |
|
351 |
collectAll:[:cls | |
|
352 |
cls isPrivate |
|
353 |
ifTrue:[#()] |
|
354 |
ifFalse:[ |
|
355 |
cls selectors |
|
356 |
select:[:sel | |
|
357 |
words conform:[:word | |
|
358 |
sel matches:word caseSensitive:false]]]] |
|
359 |
) asSet. |
|
360 |
||
361 |
showList := |
|
362 |
[:list :listName | |
|
22766 | 363 |
|showIt sortedList longest limit numCols colWidth| |
22735 | 364 |
|
365 |
showIt := true. |
|
366 |
list notEmpty ifTrue:[ |
|
367 |
list size > 20 ifTrue:[ |
|
368 |
showIt := self askYesNo:( |
|
369 |
'apropos: there are %1 matching %2; list them all (y/n)? ' |
|
370 |
bindWith:list size |
|
371 |
with:listName) |
|
372 |
] ifFalse:[ |
|
22771 | 373 |
stderr showCR:'matching %1:' with:listName. |
22735 | 374 |
]. |
375 |
showIt ifTrue:[ |
|
376 |
sortedList := list asOrderedCollection sort. |
|
377 |
longest := (list collect:[:nm | nm size]) max. |
|
378 |
limit := 78. |
|
379 |
numCols := (80 // (longest min:limit)) max:1. |
|
22766 | 380 |
colWidth := (longest min:limit). |
22735 | 381 |
sortedList slicesOf:numCols do:[:eachGroupOfN | |
22771 | 382 |
stderr |
22735 | 383 |
spaces:2; |
384 |
nextPutLine:( |
|
385 |
(eachGroupOfN |
|
386 |
collect:[:nm | |
|
22766 | 387 |
(nm contractTo:colWidth) paddedTo:colWidth |
22735 | 388 |
] |
389 |
) asStringWith:' '). |
|
390 |
]. |
|
391 |
]. |
|
392 |
]. |
|
393 |
]. |
|
394 |
||
395 |
showList value:classNamesMatching value:'classes'. |
|
396 |
showList value:selectorsMatching value:'method names'. |
|
397 |
" |
|
398 |
self basicNew |
|
399 |
input:Stdin; |
|
400 |
cmd_apropos:'Array' readStream |
|
401 |
||
402 |
self basicNew |
|
403 |
input:Stdin; |
|
404 |
cmd_apropos:'at:' readStream |
|
405 |
||
406 |
self basicNew |
|
407 |
input:Stdin; |
|
408 |
cmd_apropos:'*at:' readStream |
|
409 |
" |
|
410 |
! |
|
411 |
||
22768 | 412 |
cmd_break:lineStream |
413 |
"breakpoint directive; i.e. |
|
414 |
#break <classname> ['class'] <selector> |
|
415 |
" |
|
416 |
||
22770 | 417 |
|answer class selectorString selector method implClass| |
22768 | 418 |
|
419 |
answer := self |
|
420 |
getClassNameAndSelectorFrom:lineStream |
|
421 |
specialWords:#('all') |
|
422 |
into:[:classArg :selectorArg | |
|
423 |
class := classArg. |
|
22770 | 424 |
selectorString := selectorArg. |
22768 | 425 |
]. |
426 |
(answer == false) ifTrue:[^ self]. |
|
427 |
(answer = 'all') ifTrue:[ |
|
428 |
^ self |
|
429 |
]. |
|
430 |
||
22770 | 431 |
(selectorString isEmptyOrNil) ifTrue:[ |
22768 | 432 |
stderr nextPutLine:'usage: #break <className> [class] <selector>'. |
433 |
^ self. |
|
434 |
]. |
|
22770 | 435 |
(selector := selectorString asSymbolIfInterned) isNil ifTrue:[ |
436 |
stderr show:'no implementation of selector: '; showCR:selectorString. |
|
22768 | 437 |
^ self. |
22770 | 438 |
]. |
439 |
||
440 |
"/ stderr show:'class: '; showCR:class. |
|
441 |
"/ stderr show:'selector: '; showCR:selector. |
|
442 |
||
443 |
(method := class compiledMethodAt:selector) isNil ifTrue:[ |
|
444 |
implClass := class whichClassImplements:selector. |
|
445 |
implClass isNil ifTrue:[ |
|
22774 | 446 |
(class isMeta not and:[(implClass := class theMetaclass whichClassImplements:selector) notNil]) ifTrue:[ |
22775 | 447 |
stderr nextPutLine:('no such method\(but found one on the class-side; try "#break %1 %2")' withCRs |
22774 | 448 |
bindWith:implClass name with:selector). |
22772 | 449 |
] ifFalse:[ |
450 |
stderr nextPutLine:'no such method'. |
|
451 |
]. |
|
22770 | 452 |
^ self. |
453 |
]. |
|
22774 | 454 |
(self askYesNo:('no such method in %1, but inherited from %2.\Add breakpoint there (y/n)?' withCRs |
22770 | 455 |
bindWith:class name with:implClass name)) ifFalse:[ |
456 |
^ self |
|
457 |
]. |
|
458 |
method := implClass compiledMethodAt:selector. |
|
22768 | 459 |
]. |
460 |
MessageTracer trapMethod:method. |
|
461 |
stderr nextPutLine:'breakpoint set. Use #delete to remove.'. |
|
462 |
||
463 |
" |
|
464 |
self basicNew |
|
465 |
input:Stdin; |
|
466 |
cmd_list:'Array' readStream |
|
467 |
||
468 |
self basicNew |
|
469 |
input:Stdin; |
|
470 |
cmd_list:'Array at:put:' readStream |
|
471 |
||
472 |
self basicNew |
|
473 |
input:Stdin; |
|
474 |
cmd_list:'ReadEvalPrintLoop doIt' readStream |
|
475 |
" |
|
476 |
! |
|
477 |
||
10463 | 478 |
cmd_clear:lineStream |
10255 | 479 |
self cmd_setOrClear:lineStream to:false |
480 |
||
481 |
"Created: / 07-12-2006 / 19:04:50 / cg" |
|
482 |
! |
|
483 |
||
20900 | 484 |
cmd_debug:lineStream |
485 |
MiniDebugger enter. |
|
486 |
! |
|
487 |
||
22768 | 488 |
cmd_delete:lineStream |
489 |
"breakpoint delete directive; i.e. |
|
490 |
#delete <classname> ['class'] <selector> |
|
491 |
#delete <classname> |
|
492 |
#delete all |
|
493 |
" |
|
494 |
||
495 |
|class selector method answer count| |
|
496 |
||
497 |
answer := self |
|
498 |
getClassNameAndSelectorFrom:lineStream |
|
499 |
specialWords:#('all') |
|
500 |
into:[:classArg :selectorArg | |
|
501 |
class := classArg. |
|
502 |
selector := selectorArg. |
|
503 |
]. |
|
504 |
||
505 |
(answer == false) ifTrue:[ |
|
506 |
stderr nextPutLine:'usage: #delete <className> [class] <selector>'. |
|
507 |
stderr nextPutLine:' or: #delete <className> [class]'. |
|
508 |
stderr nextPutLine:' or: #delete all'. |
|
509 |
^ self |
|
510 |
]. |
|
511 |
(answer = 'all') ifTrue:[ |
|
512 |
MessageTracer unwrapAllMethods. |
|
513 |
^ self |
|
514 |
]. |
|
515 |
||
516 |
selector notNil ifTrue:[ |
|
517 |
(method := class compiledMethodAt:selector asSymbol) isNil ifTrue:[ |
|
518 |
stderr nextPutLine:'no such method'. |
|
519 |
^ self. |
|
520 |
]. |
|
521 |
MessageTracer unwrapMethod:method. |
|
522 |
stderr nextPutLine:'breakpoint removed.'. |
|
523 |
^ self. |
|
524 |
]. |
|
525 |
||
526 |
count := 0. |
|
527 |
class instAndClassMethodsDo:[:m | |
|
528 |
m isWrapped ifTrue:[ |
|
529 |
MessageTracer unwrapMethod:m. |
|
530 |
count := count + 1. |
|
531 |
]. |
|
532 |
]. |
|
533 |
stderr nextPutLine:('%1 breakpoints removed.' bindWith:count). |
|
534 |
||
535 |
" |
|
536 |
self basicNew |
|
537 |
input:Stdin; |
|
538 |
cmd_list:'Array' readStream |
|
539 |
||
540 |
self basicNew |
|
541 |
input:Stdin; |
|
542 |
cmd_list:'Array at:put:' readStream |
|
543 |
||
544 |
self basicNew |
|
545 |
input:Stdin; |
|
546 |
cmd_list:'ReadEvalPrintLoop doIt' readStream |
|
547 |
" |
|
548 |
! |
|
549 |
||
20900 | 550 |
cmd_edit:lineStream |
20935 | 551 |
"edit a class or selector in an external editor" |
20900 | 552 |
|
22771 | 553 |
|classOrMethodName cls methodName selector |
20906 | 554 |
code isNewClass editFullClass tmpFile modifiedTime| |
20900 | 555 |
|
20906 | 556 |
isNewClass := editFullClass := false. |
20900 | 557 |
|
558 |
lineStream skipSeparators. |
|
20926 | 559 |
lineStream atEnd ifTrue:[ |
560 |
cls := lastEditedClass. |
|
561 |
methodName := lastEditedSelector. |
|
562 |
] ifFalse:[ |
|
563 |
classOrMethodName := lineStream |
|
564 |
upToElementForWhich:[:ch | |
|
565 |
ch isLetterOrDigit not and:[ch ~~ $_] |
|
566 |
]. |
|
567 |
"/ |
|
568 |
(classOrMethodName isUppercaseFirst) ifTrue:[ |
|
569 |
(cls := Smalltalk classNamed:classOrMethodName) isNil ifTrue:[ |
|
22771 | 570 |
stderr show:'edit: no such class: ',classOrMethodName,' ; create (y/n)? '. |
20926 | 571 |
(self inputStream nextLine withoutSeparators startsWith:'y') ifFalse:[^ self]. |
572 |
isNewClass := true. |
|
573 |
code := |
|
574 |
'"/ change the code as required, then save and exit the editor. |
|
575 |
"/ To cancel this edit, leave the editor WITHOUT saving. |
|
576 |
"/ |
|
577 |
||
578 |
Object |
|
20900 | 579 |
subclass:#%1 |
580 |
instanceVariableNames:'''' |
|
581 |
classVariableNames:'''' |
|
582 |
poolDictionaries:'''' |
|
583 |
category:''user classes'' |
|
584 |
' bindWith:classOrMethodName. |
|
20926 | 585 |
] ifFalse:[ |
586 |
lineStream skipSeparators. |
|
587 |
lineStream atEnd ifFalse:[ |
|
588 |
methodName := lineStream upToSeparator. |
|
22735 | 589 |
methodName = 'class' ifTrue:[ |
590 |
cls := cls theMetaclass. |
|
591 |
lineStream skipSeparators. |
|
592 |
methodName := lineStream upToSeparator. |
|
593 |
]. |
|
20926 | 594 |
]. |
20900 | 595 |
]. |
20926 | 596 |
] ifFalse:[ |
597 |
methodName := classOrMethodName |
|
20900 | 598 |
]. |
599 |
]. |
|
20926 | 600 |
|
20900 | 601 |
isNewClass ifFalse:[ |
602 |
cls := cls ? lastEditedClass. |
|
603 |
cls isNil ifTrue:[ |
|
22771 | 604 |
stderr showCR:'edit usage:'. |
605 |
stderr showCR:' #edit className selector'. |
|
606 |
stderr showCR:' #edit className '. |
|
607 |
stderr showCR:' #edit selector (class as in previous edit)'. |
|
608 |
stderr showCR:' #edit (class/method as in previous edit)'. |
|
20900 | 609 |
^ self. |
610 |
]. |
|
611 |
lastEditedClass := cls. |
|
20926 | 612 |
lastEditedSelector := methodName. |
613 |
||
20906 | 614 |
methodName isNil ifTrue:[ |
615 |
editFullClass := true. |
|
616 |
code := cls source asString |
|
617 |
] ifFalse:[ |
|
618 |
((selector := methodName asSymbolIfInterned) isNil |
|
619 |
or:[ (cls implements:selector) not]) ifTrue:[ |
|
22735 | 620 |
(self askYesNo:('"',methodName,'" is a new method; create (y/n)? ')) ifFalse:[^ self]. |
621 |
||
20926 | 622 |
code := |
623 |
'"/ change the code as required, then save and exit the editor. |
|
624 |
"/ To cancel this edit, leave the editor WITHOUT saving. |
|
625 |
||
20900 | 626 |
%1 |
627 |
"this is a new method" |
|
628 |
self halt |
|
20906 | 629 |
' bindWith:methodName. |
630 |
] ifFalse:[ |
|
20926 | 631 |
code := (cls compiledMethodAt:selector) source. |
20906 | 632 |
]. |
20900 | 633 |
]. |
634 |
]. |
|
635 |
||
20906 | 636 |
[ |
20936 | 637 |
|ok cmd| |
20933 | 638 |
|
20906 | 639 |
tmpFile := Filename newTemporary. |
640 |
tmpFile contents:code. |
|
641 |
modifiedTime := tmpFile modificationTime. |
|
20933 | 642 |
|
20936 | 643 |
cmd := '%1 "%2"'. |
644 |
OperatingSystem isUNIXlike ifTrue:[ |
|
22767 | 645 |
cmd := '%1 "%2" </dev/tty >/dev/tty 2>&1'. |
20936 | 646 |
]. |
647 |
||
20933 | 648 |
ok := OperatingSystem |
20936 | 649 |
executeCommand:(cmd bindWith:(self editorCommand) with:tmpFile pathName) |
650 |
inputFrom:Stdin |
|
651 |
outputTo:Stdout |
|
652 |
errorTo:Stderr |
|
20933 | 653 |
auxFrom:nil |
654 |
environment:nil |
|
655 |
inDirectory:nil |
|
656 |
lineWise:false |
|
657 |
newPgrp:false |
|
658 |
showWindow:true |
|
659 |
onError:[:status | false]. |
|
660 |
||
661 |
(ok and:[tmpFile modificationTime ~= modifiedTime]) ifTrue:[ |
|
20906 | 662 |
isNewClass ifTrue:[ |
663 |
Compiler evaluate:tmpFile contentsOfEntireFile. |
|
22771 | 664 |
stderr showCR:'Class (re)defined.' |
20906 | 665 |
] ifFalse:[ |
666 |
editFullClass ifTrue:[ |
|
667 |
tmpFile fileIn. |
|
22771 | 668 |
stderr showCR:'Class (re)compiled.' |
20906 | 669 |
] ifFalse:[ |
670 |
cls compile:tmpFile contentsOfEntireFile classified:'*as yet uncategorized'. |
|
22771 | 671 |
stderr showCR:'Method (re)compiled.' |
20906 | 672 |
]. |
673 |
]. |
|
20937 | 674 |
] ifFalse:[ |
22771 | 675 |
stderr showCR:'No change.' |
20937 | 676 |
]. |
20906 | 677 |
] ensure:[ |
678 |
tmpFile notNil ifTrue:[ |
|
679 |
tmpFile remove |
|
680 |
] |
|
20900 | 681 |
]. |
20906 | 682 |
|
20900 | 683 |
" |
20934 | 684 |
Smalltalk readEvalPrintLoop |
685 |
||
20900 | 686 |
self new |
687 |
input:Stdin; |
|
688 |
cmd_edit:'MyClass foo' readStream |
|
22735 | 689 |
|
690 |
self new |
|
691 |
input:Stdin; |
|
692 |
cmd_edit:'Array class new:' readStream |
|
20900 | 693 |
" |
20933 | 694 |
|
20935 | 695 |
"Modified: / 08-11-2016 / 22:46:12 / cg" |
20900 | 696 |
! |
697 |
||
10463 | 698 |
cmd_exit:lineStream |
22576 | 699 |
"exit directive - leaves the repl" |
700 |
||
10628
284266d54dbe
#exit only leaves the rep-loop
Claus Gittinger <cg@exept.de>
parents:
10500
diff
changeset
|
701 |
exitAction value |
10463 | 702 |
|
703 |
"Created: / 07-12-2006 / 18:55:46 / cg" |
|
10255 | 704 |
! |
705 |
||
10463 | 706 |
cmd_help:lineStream |
22771 | 707 |
stderr |
20771 | 708 |
nextPutAll: |
16084 | 709 |
'Everything entered up to an empty line or a line ending in "." is called a "chunk" and evaluated. |
23684 | 710 |
Lines ending with "\” prevent the above. |
22742 | 711 |
Lines starting with "#" (in the first column) are commands to the read-eval-print interpreter. |
10463 | 712 |
|
713 |
Valid commands are: |
|
23509 | 714 |
', (OperatingSystem isOSXlike ifTrue:[ |
715 |
' #qFix ............... fix locked xQuartz display (hack) |
|
716 |
' ] ifFalse:['']) , |
|
717 |
' #exit ............... exit interpreter loop |
|
10635
c3c4fc186068
changed #interpreterLoopWith:
Claus Gittinger <cg@exept.de>
parents:
10632
diff
changeset
|
718 |
#help ............... this text |
22795 | 719 |
#usage .............. command line arguments |
22776 | 720 |
#ide ................ open the IDE |
22765 | 721 |
#apropos word ....... list classes/selectors matching word |
722 |
#list <what> ........ show source |
|
723 |
class .............. class definition and comment |
|
724 |
class selector ..... method source |
|
725 |
#read <filename>..... read another script or source file |
|
10635
c3c4fc186068
changed #interpreterLoopWith:
Claus Gittinger <cg@exept.de>
parents:
10632
diff
changeset
|
726 |
#use <package>....... use (load) a package |
20771 | 727 |
stx:libwidg .............. GUI package |
728 |
stx:libtool .............. IDE tool package |
|
729 |
stx:goodies/regex ........ regex package |
|
730 |
stx:goodies/petitparser .. peg parser package |
|
22765 | 731 |
goodies/petitparser ...... default package prefix is "stx:" |
732 |
default defaultPrefix .... change the default package prefix |
|
22775 | 733 |
#show <what> .......... show info |
734 |
variables ............ interpreter variables |
|
735 |
processes ............ processes |
|
736 |
memory ............... memory usage |
|
737 |
flags ................ flags |
|
738 |
modules .............. loaded modules |
|
739 |
packages ............. available packages to load |
|
740 |
all .................. all of the above |
|
741 |
#set <flag> ........... set a flag (value defaults to true) |
|
742 |
print ................ print return values |
|
743 |
nodebug .............. no debugger on error |
|
744 |
confirmdebug ......... ask for debugger on error |
|
745 |
trace ................ tracing execution |
|
746 |
timing ............... timing execution |
|
747 |
profiling ............ show execution profile |
|
748 |
chunkFormat .......... traditional bang chunk format input mode |
|
749 |
editor ............... command used with #edit directive |
|
750 |
prefix defPrefix ..... change the default package prefix |
|
751 |
#clear <flag> ......... same as: "#set <flag> false" |
|
752 |
#debug ................ enter a MiniDebugger |
|
753 |
#break class selector .... add a breakpoint |
|
754 |
#delete <what> ........ delete breakpoint(s) |
|
755 |
all .................. delete all breakpoints |
|
756 |
class ................ delete breakpoints in class |
|
757 |
class selector ....... delete this breakpoint |
|
758 |
#edit <what> .......... open an external editor |
|
759 |
class ................ on a class |
|
760 |
class selector ....... on a method |
|
761 |
<empty> .............. on previously edited method/last class |
|
10257 | 762 |
|
16087 | 763 |
The MiniDebugger (if entered) shows its own help with "?". |
10255 | 764 |
' |
765 |
||
766 |
"Created: / 07-12-2006 / 18:54:20 / cg" |
|
20935 | 767 |
"Modified: / 08-11-2016 / 22:53:53 / cg" |
23684 | 768 |
"Modified: / 09-02-2019 / 14:34:28 / Claus Gittinger" |
10255 | 769 |
! |
770 |
||
22768 | 771 |
cmd_ide:lineStream |
772 |
"upen up the ide" |
|
773 |
||
22778 | 774 |
|builder app| |
775 |
||
776 |
builder := NewLauncher open. |
|
777 |
builder notNil ifTrue:[ |
|
778 |
app := builder application. |
|
779 |
||
22780 | 780 |
stderr showCR:'waiting for launcher to be closed...'. |
781 |
||
22778 | 782 |
"/ don't go back into the reader, as this will slow down the |
783 |
"/ IDE (donnow why, at the moment) |
|
784 |
[ |
|
22779 | 785 |
Delay waitForSeconds:0.5. |
22778 | 786 |
app isOpen |
787 |
] whileTrue. |
|
788 |
]. |
|
22768 | 789 |
! |
790 |
||
22765 | 791 |
cmd_language:lineStream |
792 |
"language directive; i.e. |
|
793 |
#language smalltalk |
|
794 |
#language javascript |
|
795 |
" |
|
796 |
||
797 |
|lang| |
|
798 |
||
799 |
lineStream skipSeparators. |
|
800 |
lang := lineStream upToEnd withoutSeparators. |
|
801 |
lang = 'smalltalk' ifTrue:[ |
|
802 |
compiler := Compiler. |
|
803 |
^ self. |
|
804 |
]. |
|
805 |
lang = 'javascript' ifTrue:[ |
|
806 |
compiler := JavaScriptCompiler. |
|
807 |
^ self. |
|
808 |
]. |
|
809 |
||
22771 | 810 |
stderr |
22765 | 811 |
showCR:'? usage: #language smalltalk'; |
812 |
showCR:'? or: #language javascript'. |
|
813 |
! |
|
814 |
||
22735 | 815 |
cmd_list:lineStream |
816 |
"list directive; i.e. |
|
817 |
#list <classname> ['class'] <selector> |
|
818 |
" |
|
819 |
||
22771 | 820 |
|class selector source| |
22735 | 821 |
|
822 |
(self |
|
22768 | 823 |
getClassNameAndSelectorFrom:lineStream |
824 |
specialWords:nil |
|
22735 | 825 |
into:[:classArg :selectorArg | |
826 |
class := classArg. |
|
827 |
selector := selectorArg. |
|
828 |
]) ifFalse:[^ self]. |
|
829 |
||
830 |
selector isNil ifTrue:[ |
|
22771 | 831 |
stderr nextPutAll:(class definition); cr. |
832 |
stderr nextPutAll:(class commentOrDocumentationString); cr. |
|
22735 | 833 |
] ifFalse:[ |
834 |
source := class sourceCodeAt:selector asSymbol. |
|
835 |
source isEmptyOrNil ifTrue:[ |
|
22771 | 836 |
stderr nextPutLine:'Sorry, no sourcecode found' |
22735 | 837 |
] ifFalse:[ |
22771 | 838 |
stderr nextPutAll:source; cr |
22735 | 839 |
]. |
840 |
]. |
|
841 |
||
842 |
" |
|
22775 | 843 |
(ReadEvalPrintLoop basicNew error:Stderr) |
22735 | 844 |
input:Stdin; |
845 |
cmd_list:'Array' readStream |
|
846 |
||
22775 | 847 |
(ReadEvalPrintLoop basicNew error:Stderr) |
22735 | 848 |
input:Stdin; |
849 |
cmd_list:'Array at:put:' readStream |
|
22764 | 850 |
|
22775 | 851 |
(ReadEvalPrintLoop basicNew error:Stderr) |
22764 | 852 |
input:Stdin; |
853 |
cmd_list:'ReadEvalPrintLoop doIt' readStream |
|
22735 | 854 |
" |
855 |
! |
|
856 |
||
23509 | 857 |
cmd_qFix:lineStream |
858 |
"qFix: |
|
23518 | 859 |
fix for a bug in xQuartz, which locks up my screen completely |
860 |
from time to time (happens when doing popup views). |
|
23509 | 861 |
It seems that iconifying all views helps (for whatever reason) |
862 |
to get out of the deadlock which results from a race condition in |
|
23518 | 863 |
grabFocus/grabPointer" |
23509 | 864 |
|
865 |
TopView allSubInstancesDo:[:t| t isPopUpView ifFalse:[ t collapse ]]. |
|
866 |
Delay waitForSeconds:1. |
|
867 |
Transcript topView expand; raise. |
|
23518 | 868 |
'Please exit the REPL now, and press ''c'' to continue' printCR. |
23509 | 869 |
|
870 |
"Created: / 05-11-2018 / 14:33:59 / Claus Gittinger" |
|
23518 | 871 |
"Modified: / 07-11-2018 / 19:53:03 / Claus Gittinger" |
23509 | 872 |
! |
873 |
||
16087 | 874 |
cmd_read:lineStream |
22577 | 875 |
"read directive; i.e. |
876 |
#read scriptFile |
|
877 |
" |
|
878 |
||
22765 | 879 |
|filename newInput |
880 |
savedPrompt savedPrint savedInput savedCurrentDirectory savedDoChunkFormat |
|
881 |
savedTraceFlag savedProfileFlag savedNoDebugger| |
|
16087 | 882 |
|
883 |
lineStream skipSeparators. |
|
884 |
filename := lineStream upToEnd withoutSeparators. |
|
22577 | 885 |
filename isEmptyOrNil ifTrue:[ |
22771 | 886 |
stderr showCR:'? usage: #read <filename>'. |
20909 | 887 |
^ self. |
16133 | 888 |
]. |
16087 | 889 |
|
20915 | 890 |
currentDirectory := currentDirectory ? (Filename currentDirectory). |
891 |
||
16087 | 892 |
filename := filename asFilename. |
893 |
filename isAbsolute ifFalse:[ |
|
20909 | 894 |
filename := currentDirectory construct:filename. |
16087 | 895 |
]. |
896 |
||
20922 | 897 |
StreamError ignoreIn:[ |
898 |
newInput := filename readStream. |
|
899 |
]. |
|
16087 | 900 |
newInput isNil ifTrue:[ |
22771 | 901 |
stderr showCR:('Could not find file: "',filename pathName,'"'). |
20909 | 902 |
^ self. |
16087 | 903 |
]. |
904 |
||
905 |
[ |
|
20909 | 906 |
savedCurrentDirectory := currentDirectory. |
20912 | 907 |
savedDoChunkFormat := doChunkFormat. |
22765 | 908 |
savedTraceFlag := traceFlag. |
909 |
savedProfileFlag := profilingFlag. |
|
20909 | 910 |
savedInput := inputStream. |
911 |
savedPrint := printFlag. |
|
912 |
savedPrompt := prompt. |
|
16087 | 913 |
|
20909 | 914 |
currentDirectory := filename directory. |
915 |
inputStream := newInput. |
|
22765 | 916 |
prompt := nil. |
917 |
||
20909 | 918 |
self |
919 |
basicReadEvalPrintLoopWithInput:newInput |
|
920 |
output:outputStream |
|
921 |
error:errorStream |
|
20910 | 922 |
compiler:(compiler ? Compiler ? Parser) |
20909 | 923 |
prompt:false |
924 |
print:false. |
|
16087 | 925 |
] ensure:[ |
20914 | 926 |
newInput close. |
20912 | 927 |
doChunkFormat := savedDoChunkFormat. |
20909 | 928 |
currentDirectory := savedCurrentDirectory. |
22765 | 929 |
traceFlag := savedTraceFlag. |
930 |
profilingFlag := savedProfileFlag. |
|
20909 | 931 |
inputStream := savedInput. |
932 |
printFlag := savedPrint. |
|
20912 | 933 |
prompt := savedPrompt. |
16087 | 934 |
]. |
935 |
! |
|
936 |
||
10463 | 937 |
cmd_set:lineStream |
10255 | 938 |
self cmd_setOrClear:lineStream to:true |
939 |
||
940 |
"Modified: / 07-12-2006 / 19:04:46 / cg" |
|
941 |
! |
|
942 |
||
10463 | 943 |
cmd_setOrClear:lineStream to:aBoolean |
22735 | 944 |
"set/clear one of my internal flags" |
945 |
||
22765 | 946 |
|what flag| |
22753 | 947 |
|
948 |
flag := aBoolean. |
|
10463 | 949 |
|
950 |
lineStream skipSeparators. |
|
951 |
what := lineStream nextAlphaNumericWord. |
|
22765 | 952 |
|
953 |
lineStream skipSeparators. |
|
954 |
||
955 |
"/ peek ahead for "false" |
|
956 |
"/ so we can also say: #set <flag> f |
|
22753 | 957 |
flag ifTrue:[ |
958 |
lineStream atEnd ifFalse:[ |
|
22765 | 959 |
flag := (lineStream peek == $f) not. |
22753 | 960 |
]. |
961 |
]. |
|
962 |
||
16133 | 963 |
what notNil ifTrue:[ |
20771 | 964 |
(what startsWith:'tra') ifTrue:[ |
22753 | 965 |
traceFlag := flag. |
20771 | 966 |
^ self. |
967 |
]. |
|
968 |
(what startsWith:'tim') ifTrue:[ |
|
22753 | 969 |
timingFlag := flag. |
20771 | 970 |
^ self. |
971 |
]. |
|
22765 | 972 |
(what startsWith:'prof') ifTrue:[ |
22753 | 973 |
profilingFlag := flag. |
20771 | 974 |
^ self. |
975 |
]. |
|
976 |
(what startsWith:'chunk') ifTrue:[ |
|
22753 | 977 |
doChunkFormat := flag. |
20771 | 978 |
^ self. |
979 |
]. |
|
20935 | 980 |
(what startsWith:'edi') ifTrue:[ |
22753 | 981 |
flag ifTrue:[ |
22765 | 982 |
"/ #set editor <cmd> |
20935 | 983 |
lineStream skipSeparators. |
22765 | 984 |
editorCommand := lineStream upToEnd withoutSeparators. |
20935 | 985 |
] ifFalse:[ |
986 |
editorCommand := nil. |
|
20938 | 987 |
]. |
988 |
^ self. |
|
20935 | 989 |
]. |
22735 | 990 |
(what startsWith:'con') ifTrue:[ |
22753 | 991 |
confirmDebugger := flag. |
22735 | 992 |
^ self. |
993 |
]. |
|
22747 | 994 |
(what startsWith:'node') ifTrue:[ |
22753 | 995 |
noDebugger := flag. |
22746 | 996 |
^ self. |
997 |
]. |
|
22743 | 998 |
(what startsWith:'pri') ifTrue:[ |
22753 | 999 |
printFlag := flag. |
22743 | 1000 |
^ self. |
1001 |
]. |
|
22765 | 1002 |
(what startsWith:'prom') ifTrue:[ |
1003 |
flag ifTrue:[ |
|
1004 |
"/ #set prompt <prompt> |
|
1005 |
self prompt:(lineStream upToEnd withoutSeparators). |
|
1006 |
] ifFalse:[ |
|
1007 |
"/ #clear prompt |
|
1008 |
self prompt:nil |
|
1009 |
]. |
|
1010 |
^ self. |
|
1011 |
]. |
|
1012 |
(what startsWith:'ans') ifTrue:[ |
|
1013 |
flag ifTrue:[ |
|
1014 |
"/ #set returnprompt <cmd> |
|
1015 |
lineStream skipSeparators. |
|
1016 |
self answerPrompt:(lineStream upToEnd withoutSeparators). |
|
1017 |
] ifFalse:[ |
|
1018 |
"/ #clear the answer prompt |
|
1019 |
self answerPrompt:''. |
|
1020 |
]. |
|
1021 |
^ self. |
|
1022 |
]. |
|
10463 | 1023 |
]. |
22771 | 1024 |
stderr |
22735 | 1025 |
showCR:'? usage: set/clear <flag>'; |
22765 | 1026 |
showCR:'? (<flag> must be one of: print, nodebug, confirmdebug, trace, times, profile, chunk, prompt, answerprompt, editor)'. |
22749 | 1027 |
self cmd_show:('flags' readStream). |
10255 | 1028 |
|
20935 | 1029 |
"Modified: / 08-11-2016 / 22:49:17 / cg" |
10255 | 1030 |
! |
1031 |
||
10463 | 1032 |
cmd_show:lineStream |
22575 | 1033 |
"show directive: |
1034 |
show packages |
|
1035 |
show modules (= loaded packages) |
|
1036 |
show variables |
|
1037 |
etc. |
|
1038 |
" |
|
1039 |
||
22771 | 1040 |
|what showAll ok| |
16087 | 1041 |
|
10463 | 1042 |
lineStream skipSeparators. |
1043 |
what := lineStream nextAlphaNumericWord. |
|
20834 | 1044 |
ok := false. |
1045 |
||
16133 | 1046 |
what notNil ifTrue:[ |
20834 | 1047 |
showAll := (what startsWith:'all'). |
1048 |
||
20835 | 1049 |
(showAll or:[ what startsWith:'var' ]) ifTrue:[ |
22771 | 1050 |
stderr showCR:'Variables:'; showCR:'----------'. |
20901 | 1051 |
self showVariables. |
20845 | 1052 |
ok := true. |
20768 | 1053 |
]. |
20845 | 1054 |
|
20835 | 1055 |
(showAll or:[ what startsWith:'proc' ]) ifTrue:[ |
22771 | 1056 |
stderr cr; showCR:'Threads:'; showCR:'--------'. |
20768 | 1057 |
MiniDebugger basicNew showProcesses. |
20845 | 1058 |
ok := true. |
20768 | 1059 |
]. |
20845 | 1060 |
|
20902 | 1061 |
("showAll or:[" what startsWith:'pack' "]") ifTrue:[ |
22771 | 1062 |
stderr cr; showCR:'Available Packages:'; showCR:'--------'. |
20900 | 1063 |
self showPackages. |
1064 |
ok := true. |
|
1065 |
]. |
|
1066 |
||
20834 | 1067 |
(showAll or:[ what startsWith:'mod' ]) ifTrue:[ |
22771 | 1068 |
stderr cr; showCR:'Modules:'; showCR:'--------'. |
20901 | 1069 |
self showModules. |
13865 | 1070 |
|
20845 | 1071 |
ok := true. |
20768 | 1072 |
]. |
20845 | 1073 |
|
20834 | 1074 |
(showAll or:[ what startsWith:'mem' ]) ifTrue:[ |
1075 |
|allMem| |
|
1076 |
||
22771 | 1077 |
stderr cr; showCR:'Memory:'; showCR:'-------'. |
20891 | 1078 |
"/ allMem := ObjectMemory oldSpaceUsed + ObjectMemory symSpaceUsed |
1079 |
"/ + ObjectMemory newSpaceUsed. |
|
22771 | 1080 |
stderr |
20923 | 1081 |
"/ showCR:('overall: ',(allMem // 1024) printString,' Kb'); |
1082 |
showCR:('used : ',(ObjectMemory bytesUsed // 1024) printString,' Kb'); |
|
1083 |
showCR:('free : ',(ObjectMemory freeSpace // 1024) printString,' Kb'); |
|
1084 |
show:('minorGC: ',(ObjectMemory scavengeCount) printString); |
|
1085 |
showCR:(' majorGC: ',(ObjectMemory garbageCollectCount) printString). |
|
20845 | 1086 |
ok := true. |
20768 | 1087 |
]. |
20845 | 1088 |
|
22775 | 1089 |
(showAll or:[ what startsWith:'bre' ]) ifTrue:[ |
1090 |
stderr cr; showCR:'Breakpoints:'; showCR:'--------'. |
|
1091 |
self showBreakpoints. |
|
1092 |
||
1093 |
ok := true. |
|
1094 |
]. |
|
1095 |
||
20834 | 1096 |
(showAll or:[ what startsWith:'flag' ]) ifTrue:[ |
22771 | 1097 |
stderr cr; showCR:'Flags:'; showCR:'------'. |
1098 |
stderr |
|
22754 | 1099 |
showCR:('print: ',self printFlag printString); |
1100 |
showCR:('nodebug: ',self noDebugger printString); |
|
1101 |
showCR:('confirmdebug:',self confirmDebugger printString); |
|
20923 | 1102 |
showCR:('trace : ',(traceFlag ? false) printString); |
1103 |
showCR:('timing: ',(timingFlag ? false) printString); |
|
1104 |
showCR:('profiling: ',(profilingFlag ? false) printString); |
|
20935 | 1105 |
showCR:('chunkFormat: ',(doChunkFormat ? false) printString); |
22735 | 1106 |
showCR:('editor: ',self editorCommand printString); |
22765 | 1107 |
showCR:('prefix: ',self defaultPackagePrefix printString); |
1108 |
showCR:('prompt: ',prompt printString); |
|
1109 |
showCR:('answerprompt:',self answerPrompt printString); |
|
22754 | 1110 |
yourself. |
20845 | 1111 |
ok := true. |
20768 | 1112 |
]. |
10463 | 1113 |
]. |
1114 |
||
20834 | 1115 |
ok ifFalse:[ |
22771 | 1116 |
stderr showCR:'? usage: show <what>'. |
1117 |
stderr showCR:'? (<what> must be one of: packages, modules, variables, flags, memory, processes)'. |
|
20834 | 1118 |
]. |
1119 |
||
1120 |
" |
|
22775 | 1121 |
(ReadEvalPrintLoop basicNew error:Stderr) cmd_show:'packages' readStream |
20834 | 1122 |
" |
10255 | 1123 |
|
20935 | 1124 |
"Modified: / 08-11-2016 / 22:46:51 / cg" |
10255 | 1125 |
! |
1126 |
||
22795 | 1127 |
cmd_usage:lineStream |
1128 |
stderr |
|
1129 |
nextPutAll:'usage: ',OperatingSystem nameOfSTXExecutable asFilename baseName,' [options...] |
|
1130 |
--help .................. output full detailed usage info. |
|
22796 | 1131 |
-R / --repl ............. read-eval-print-loop |
1132 |
-E / --eval <expr> ...... eval expr, then exit |
|
1133 |
-P / --print <expr> ..... eval expr, print, then exit |
|
1134 |
-f / --execute <file> ... eval exprs from file, then exit |
|
1135 |
-l / --load <file> ...... load file before starting |
|
1136 |
-q / --silent ........... suppress messages (& prompts in repl) |
|
22795 | 1137 |
|
1138 |
For a full list of options, please take a look at the documentation |
|
1139 |
in "doc/online/english/getstart/TOP.html". |
|
1140 |
' |
|
1141 |
! |
|
1142 |
||
10463 | 1143 |
cmd_use:lineStream |
22574 | 1144 |
"use directive; i.e. |
1145 |
#use stx:goodies/xml |
|
1146 |
#use exept:mqtt |
|
22765 | 1147 |
#use goodies/regression |
22574 | 1148 |
" |
1149 |
||
22765 | 1150 |
|pkg s defaultPrefix| |
10463 | 1151 |
|
1152 |
lineStream skipSeparators. |
|
22765 | 1153 |
pkg := lineStream upToEnd withoutSeparators. |
1154 |
pkg isEmpty ifTrue:[ |
|
22771 | 1155 |
stderr |
22765 | 1156 |
showCR:'? usage: #use <package>'; |
1157 |
showCR:'? or: #use default <packagePrefix>'. |
|
1158 |
^ self. |
|
1159 |
]. |
|
1160 |
||
1161 |
s := pkg readStream. |
|
1162 |
(s nextAlphaNumericWord) = 'default' ifTrue:[ |
|
1163 |
defaultPrefix := s upToEnd withoutSeparators. |
|
1164 |
self defaultPackagePrefix:defaultPrefix. |
|
20923 | 1165 |
^ self. |
16133 | 1166 |
]. |
1167 |
||
16145 | 1168 |
[ |
20923 | 1169 |
Smalltalk loadPackage:pkg. |
16145 | 1170 |
] on:PackageLoadError do:[:ex| |
20923 | 1171 |
"/ allow for some shortcuts... |
1172 |
(pkg includes:$:) ifTrue:[ |
|
22771 | 1173 |
stderr showCR:('Failed to load package: "',pkg,'"'). |
20923 | 1174 |
] ifFalse:[ |
1175 |
"/ try stx standard package |
|
22765 | 1176 |
pkg := (self defaultPackagePrefix), pkg. |
20923 | 1177 |
ex restart. |
1178 |
]. |
|
13852 | 1179 |
]. |
10255 | 1180 |
|
1181 |
"Created: / 07-12-2006 / 19:07:56 / cg" |
|
10463 | 1182 |
! |
1183 |
||
1184 |
directive:line |
|
1185 |
|s cmd| |
|
1186 |
||
1187 |
s := line readStream. |
|
1188 |
s next. "/ skip the hash |
|
20913 | 1189 |
s peek == $!! ifTrue:[ |
1190 |
"/ skip shebang line |
|
1191 |
^ self. |
|
1192 |
]. |
|
10463 | 1193 |
s skipSeparators. |
1194 |
||
1195 |
cmd := s nextAlphaNumericWord. |
|
16087 | 1196 |
cmd notNil ifTrue:[ |
20919 | 1197 |
AbortAllOperationRequest handle:[:ex | |
22771 | 1198 |
stderr showCR:('Directive aborted: ', ex description) |
20919 | 1199 |
] do:[ |
20920 | 1200 |
Error handle:[:ex | |
22771 | 1201 |
stderr showCR:('Caught in directive: ', ex description). |
20926 | 1202 |
ex suspendedContext fullPrintAll. |
20919 | 1203 |
] do:[ |
20926 | 1204 |
ControlInterrupt handle:[:ex | |
20936 | 1205 |
MiniDebugger enter. |
22771 | 1206 |
"/ stderr showCR:('Ignored in directive: ', ex description). |
20936 | 1207 |
"/ ex reject. |
1208 |
"/ ex proceed. |
|
20926 | 1209 |
] do:[ |
1210 |
self |
|
1211 |
perform:('cmd_',cmd) asMutator with:s |
|
1212 |
ifNotUnderstood:[ |
|
22771 | 1213 |
stderr |
22739 | 1214 |
showCR:'?? invalid command: %1. Type "#help" for help.' with:cmd. |
20926 | 1215 |
]. |
1216 |
]. |
|
20913 | 1217 |
]. |
20919 | 1218 |
]. |
16087 | 1219 |
]. |
10463 | 1220 |
|
1221 |
"Created: / 07-12-2006 / 18:49:17 / cg" |
|
20933 | 1222 |
"Modified: / 08-11-2016 / 21:59:16 / cg" |
20900 | 1223 |
! |
1224 |
||
22768 | 1225 |
getClassNameAndSelectorFrom:lineStream specialWords:specialWords into:aBlock |
22735 | 1226 |
"a helper for list and edit; parses class and selector name. |
22768 | 1227 |
if the argument is one of the specialWords, return it. |
1228 |
otherwise, returns true if class/selector are ok, |
|
1229 |
or false if nothing reasonable was entered" |
|
22735 | 1230 |
|
1231 |
|words wordStream className class selector| |
|
1232 |
||
1233 |
lineStream skipSeparators. |
|
1234 |
words := lineStream upToEnd asCollectionOfWords. |
|
1235 |
||
1236 |
(words isEmpty) ifTrue:[ |
|
1237 |
^ false. |
|
1238 |
]. |
|
1239 |
||
1240 |
wordStream := words readStream. |
|
1241 |
||
1242 |
"/ search in classes: |
|
1243 |
className := wordStream next. |
|
22768 | 1244 |
((specialWords ? #()) includes:className) ifTrue:[ |
1245 |
^ className |
|
1246 |
]. |
|
1247 |
||
22735 | 1248 |
class := Smalltalk classNamed:className. |
1249 |
class isNil ifTrue:[ |
|
22771 | 1250 |
stderr showCR:'no such class: ',className. |
22735 | 1251 |
^ false. |
1252 |
]. |
|
1253 |
||
1254 |
(wordStream atEnd not and:[wordStream peek = 'class']) ifTrue:[ |
|
1255 |
wordStream next. |
|
1256 |
class := class theMetaclass |
|
1257 |
]. |
|
1258 |
(wordStream atEnd) ifFalse:[ |
|
1259 |
selector := wordStream next. |
|
1260 |
]. |
|
1261 |
aBlock value:class value:selector. |
|
1262 |
^ true |
|
1263 |
! |
|
1264 |
||
22775 | 1265 |
showBreakpoints |
1266 |
Smalltalk allClassesDo:[:cls | |
|
1267 |
cls theNonMetaclass instAndClassSelectorsAndMethodsDo:[:sel :mthd | |
|
1268 |
mthd isWrapped ifTrue:[ |
|
22776 | 1269 |
stderr showCR:(mthd whoString) |
22775 | 1270 |
]. |
1271 |
]. |
|
1272 |
]. |
|
1273 |
||
1274 |
" |
|
1275 |
(ReadEvalPrintLoop basicNew error:Stderr) showBreakpoints |
|
1276 |
" |
|
1277 |
! |
|
1278 |
||
20901 | 1279 |
showModules |
22775 | 1280 |
"lists loaded packages" |
1281 |
||
22771 | 1282 |
|printModule| |
20901 | 1283 |
|
1284 |
printModule := |
|
1285 |
[:mod | |
|
22775 | 1286 |
self errorStream |
20923 | 1287 |
show:' '; |
1288 |
show:(mod package "libraryName"); |
|
1289 |
showCR:' (',(mod type),')'. |
|
20901 | 1290 |
]. |
1291 |
||
22771 | 1292 |
stderr nextPutLine:'builtIn:'. |
20901 | 1293 |
((ObjectMemory binaryModuleInfo |
1294 |
reject:[:m | m dynamic]) |
|
1295 |
asSortedCollection:[:a :b | a name < b name]) do:printModule. |
|
1296 |
||
22771 | 1297 |
stderr nextPutLine:'dynamic:'. |
20901 | 1298 |
((ObjectMemory binaryModuleInfo |
1299 |
select:[:m | m dynamic]) |
|
1300 |
asSortedCollection:[:a :b | a name < b name]) do:printModule. |
|
1301 |
||
1302 |
" |
|
22775 | 1303 |
(ReadEvalPrintLoop basicNew error:Stderr) showModules |
20901 | 1304 |
" |
1305 |
! |
|
1306 |
||
20900 | 1307 |
showPackages |
22775 | 1308 |
"lists all known packages" |
1309 |
||
20900 | 1310 |
|all| |
1311 |
||
1312 |
all := Set new. |
|
1313 |
Smalltalk knownLoadablePackagesDo:[:packageID :type :path | |
|
1314 |
all add:packageID |
|
1315 |
]. |
|
1316 |
all := all asOrderedCollection sort. |
|
1317 |
all do:[:eachPackage | |
|
22771 | 1318 |
stderr show:eachPackage. |
20901 | 1319 |
(Smalltalk isPackageLoaded:eachPackage) ifTrue:[ |
22771 | 1320 |
stderr show:' (loaded)'. |
20901 | 1321 |
]. |
22771 | 1322 |
stderr cr. |
20900 | 1323 |
]. |
1324 |
||
1325 |
" |
|
22775 | 1326 |
(ReadEvalPrintLoop basicNew error:Stderr) showPackages |
1327 |
(ReadEvalPrintLoop basicNew error:Stderr) showModules |
|
20901 | 1328 |
" |
1329 |
! |
|
1330 |
||
1331 |
showVariables |
|
1332 |
Workspace notNil ifTrue:[ |
|
1333 |
Workspace workspaceVariables keys asOrderedCollection sort do:[:nm | |
|
1334 |
|holder| |
|
22771 | 1335 |
|
20901 | 1336 |
holder := Workspace workspaceVariables at:nm. |
22771 | 1337 |
stderr |
20923 | 1338 |
show:nm; |
1339 |
show:' -> '; |
|
1340 |
showCR:holder value printString. |
|
20901 | 1341 |
]. |
1342 |
]. |
|
1343 |
||
1344 |
" |
|
22775 | 1345 |
(ReadEvalPrintLoop basicNew error:Stderr) showVariables |
20900 | 1346 |
" |
10255 | 1347 |
! ! |
1348 |
||
23684 | 1349 |
!ReadEvalPrintLoop methodsFor:'doit'! |
1350 |
||
1351 |
doIt ^[123 |
|
1352 |
||
1353 |
+ |
|
1354 |
||
1355 |
234 |
|
1356 |
.] value |
|
1357 |
! ! |
|
1358 |
||
10248 | 1359 |
!ReadEvalPrintLoop methodsFor:'evaluation'! |
1360 |
||
16565 | 1361 |
basicReadEvalPrintLoopWithInput:input output:output error:error |
22762 | 1362 |
compiler:compilerClass prompt:doPrompt print:doPrint |
16087 | 1363 |
|
1364 |
"{ Pragma: +optSpace }" |
|
1365 |
||
22735 | 1366 |
"the core of the interpreter loop; |
1367 |
extracted and parametrized, so it can be called recursively for included scripts. |
|
16087 | 1368 |
If chunkFormat is true, chunks are read. |
23684 | 1369 |
Otherwise, lines up to an empty line (or EOF) or a line ending in '.' are read, |
1370 |
unless the line ends with '\'. |
|
20774 | 1371 |
A '#' character appearing in the first column of the first line turns off chunkmode, |
1372 |
which allows for convenient shell scripts containing a #/bin/stx as the first line." |
|
16087 | 1373 |
|
20911 | 1374 |
exitAction := [^ self]. |
1375 |
||
16087 | 1376 |
[ |
20769 | 1377 |
|lines chunk| |
16087 | 1378 |
|
22762 | 1379 |
(doPrompt and:[prompt notEmptyOrNil]) ifTrue:[ |
20935 | 1380 |
error show:prompt. |
20769 | 1381 |
]. |
16087 | 1382 |
|
20769 | 1383 |
input atEnd ifTrue:[ |
20912 | 1384 |
doPrint ifTrue:[ error cr ]. |
20769 | 1385 |
^ self. |
1386 |
]. |
|
16087 | 1387 |
|
20769 | 1388 |
input peek == $# ifTrue:[ |
1389 |
self doChunkFormat:false. |
|
1390 |
]. |
|
16087 | 1391 |
|
20769 | 1392 |
self doChunkFormat ifTrue:[ |
1393 |
input skipSeparators. |
|
1394 |
chunk := input nextChunk. |
|
1395 |
] ifFalse:[ |
|
1396 |
lines := OrderedCollection new. |
|
1397 |
[ |
|
23684 | 1398 |
|line stillReading| |
16087 | 1399 |
|
23684 | 1400 |
stillReading := false. |
20769 | 1401 |
line := input nextLine. |
1402 |
line notEmptyOrNil ifTrue:[ |
|
1403 |
line = '?' ifTrue:[ |
|
1404 |
self cmd_help:nil. |
|
22762 | 1405 |
doPrompt notNil ifTrue:[ |
20935 | 1406 |
error show:prompt. |
20769 | 1407 |
]. |
1408 |
] ifFalse:[ |
|
1409 |
(line startsWith:'#') ifTrue:[ |
|
1410 |
self directive:line. |
|
22762 | 1411 |
(doPrompt and:[prompt notEmptyOrNil]) ifTrue:[ |
20935 | 1412 |
error show:prompt. |
20769 | 1413 |
]. |
1414 |
] ifFalse:[ |
|
23684 | 1415 |
(line endsWith:'\') ifTrue:[ |
1416 |
stillReading := true. |
|
1417 |
line := line copyButLast. |
|
1418 |
]. |
|
20769 | 1419 |
lines add:line. |
1420 |
] |
|
1421 |
] |
|
1422 |
]. |
|
23684 | 1423 |
stillReading ifFalse:[ |
1424 |
stillReading := line notEmptyOrNil and:[(line endsWith:$.) not] |
|
1425 |
]. |
|
1426 |
stillReading |
|
20769 | 1427 |
] whileTrue. |
1428 |
chunk := lines asStringWith:Character cr. |
|
1429 |
]. |
|
16087 | 1430 |
|
20890 | 1431 |
(chunk notEmptyOrNil |
1432 |
and:[chunk withoutSeparators notEmpty |
|
1433 |
and:[chunk withoutSeparators ~= '.']] |
|
1434 |
) ifTrue:[ |
|
22765 | 1435 |
self compileAndExexute:chunk with:compilerClass doPrompt:doPrompt doPrint:doPrint. |
20769 | 1436 |
]. |
16087 | 1437 |
] loop. |
1438 |
||
1439 |
" |
|
20935 | 1440 |
Smalltalk readEvalPrintLoop. |
1441 |
||
22764 | 1442 |
(ReadEvalPrintLoop new |
1443 |
doChunkFormat:false; |
|
1444 |
prompt:'>') readEvalPrintLoop |
|
16087 | 1445 |
" |
1446 |
||
1447 |
"Created: / 07-12-2006 / 17:27:21 / cg" |
|
20935 | 1448 |
"Modified: / 08-11-2016 / 22:41:47 / cg" |
23684 | 1449 |
"Modified (comment): / 09-02-2019 / 14:30:50 / Claus Gittinger" |
16087 | 1450 |
! |
1451 |
||
22765 | 1452 |
compileAndExexute:chunk with:compilerClass doPrompt:doPrompt doPrint:doPrint |
22764 | 1453 |
"abortAll is handled, but not asked for here!!" |
1454 |
AbortAllOperationRequest handle:[:ex | |
|
1455 |
ObjectMemory sendTraceOff. |
|
1456 |
stderr nextPutLine:('Evaluation aborted.') |
|
1457 |
] do:[ |
|
1458 |
(Error, ControlInterrupt) handle:[:ex | |
|
1459 |
ObjectMemory sendTraceOff. |
|
1460 |
doPrompt ifFalse:[ |
|
1461 |
ex reject |
|
1462 |
]. |
|
1463 |
(self noDebugger |
|
1464 |
and:[ ex creator isControlInterrupt not]) ifTrue:[ |
|
1465 |
stderr showCR:('Evaluation aborted: ', ex description). |
|
1466 |
] ifFalse:[ |
|
1467 |
(self confirmDebugger not |
|
1468 |
or:[ ex creator isControlInterrupt |
|
1469 |
or:[ self askYesNo:('Error encountered: %1\Debug (y/n)? ' |
|
1470 |
withCRs bindWith:ex description)]] |
|
1471 |
) ifTrue:[ |
|
1472 |
MiniDebugger enterWithMessage:(ex errorString) mayProceed:true. |
|
1473 |
"/ if we arrive here, user typed 'c' - continue |
|
1474 |
ex mayProceed ifTrue:[ |
|
1475 |
ex proceed. |
|
1476 |
]. |
|
1477 |
]. |
|
1478 |
]. |
|
1479 |
ex return. |
|
1480 |
] do:[ |
|
1481 |
|value ms us mthd| |
|
1482 |
||
22903 | 1483 |
Class withoutUpdatingChangesDo:[ |
1484 |
mthd := compilerClass |
|
1485 |
compile:('doIt ^[',chunk,'] value') forClass:(self class) |
|
1486 |
inCategory:'doit' notifying:self |
|
1487 |
install:true. |
|
1488 |
]. |
|
22763 | 1489 |
|
22764 | 1490 |
mthd isMethod ifTrue:[ |
1491 |
traceFlag == true ifTrue:[ |
|
24106 | 1492 |
MessageTracer debugTrace:[ |
22903 | 1493 |
value := self doIt. "/ not here now, but dynamically created |
22764 | 1494 |
] |
1495 |
] ifFalse:[ |
|
1496 |
profilingFlag == true ifTrue:[ |
|
1497 |
MessageTally spyDetailedOn:[ |
|
22903 | 1498 |
value := self doIt. "/ not here now, but dynamically created |
22764 | 1499 |
]. |
1500 |
] ifFalse:[ |
|
1501 |
us := Time microsecondsToRun:[ |
|
22903 | 1502 |
value := self doIt. "/ not here now, but dynamically created |
22764 | 1503 |
]. |
1504 |
||
1505 |
timingFlag == true ifTrue:[ |
|
1506 |
'execution time: ' printOn:stderr. |
|
1507 |
us < 1000 ifTrue:[ |
|
1508 |
us < 1 ifTrue:[ |
|
1509 |
stderr nextPutLine:'too small to measure (<1us)'. |
|
1510 |
] ifFalse:[ |
|
1511 |
stderr print:us; nextPutLine:'us'. |
|
1512 |
] |
|
1513 |
] ifFalse:[ |
|
1514 |
stderr print:((us / 1000) asFixedPoint:2); nextPutLine:'ms'. |
|
1515 |
]. |
|
1516 |
]. |
|
1517 |
]. |
|
1518 |
]. |
|
1519 |
(doPrint and:[self printFlag]) ifTrue:[ |
|
1520 |
value isVoid ifFalse:[ |
|
22765 | 1521 |
stderr nextPutAll:(self answerPrompt). |
22764 | 1522 |
stderr nextPutLine:(value displayString). |
1523 |
]. |
|
1524 |
]. |
|
1525 |
Workspace notNil ifTrue:[ |
|
1526 |
Workspace rememberResultAsWorkspaceVariable:value. |
|
1527 |
]. |
|
1528 |
]. |
|
1529 |
]. |
|
1530 |
]. |
|
24106 | 1531 |
|
1532 |
"Modified: / 04-05-2019 / 15:51:16 / Claus Gittinger" |
|
22763 | 1533 |
! |
1534 |
||
10463 | 1535 |
readEvalPrintLoop |
1536 |
"{ Pragma: +optSpace }" |
|
1537 |
||
1538 |
"simple read-eval-print loop for non-graphical Minitalk. |
|
1539 |
If the chunkFormat-argument is true, chunks are read. |
|
16087 | 1540 |
Otherwise, lines up to an empty line (or EOF) are read. |
1541 |
A '#' character appearing in the first column of the first line |
|
22781 | 1542 |
switches to non-chunkMode." |
10463 | 1543 |
|
1544 |
ControlInterrupt handle:[:ex | |
|
20935 | 1545 |
self errorStream showCR:('Caught: ', ex description). |
20833 | 1546 |
self inputStream atEnd ifTrue:[ |
1547 |
ex return. |
|
1548 |
]. |
|
20933 | 1549 |
MiniDebugger enter. |
1550 |
ex proceed. |
|
1551 |
"/ ex restart. |
|
10463 | 1552 |
] do:[ |
22764 | 1553 |
|compilerClass| |
20774 | 1554 |
|
1555 |
"/ re-evaluate these in the loop, so they can be changed dynamically |
|
22764 | 1556 |
stdin := self inputStream. |
1557 |
stdout := self outputStream. |
|
1558 |
stderr := self errorStream. |
|
10463 | 1559 |
|
20774 | 1560 |
compilerClass := compiler ? Compiler ? Parser. |
1561 |
compilerClass isNil ifTrue:[ |
|
22764 | 1562 |
stderr showCR:('oops - no Compiler class found'). |
20774 | 1563 |
^ self. |
1564 |
]. |
|
1565 |
StreamError handle:[:ex | |
|
22764 | 1566 |
(stdin isOpen not or:[stdin atEnd]) ifTrue:[ |
1567 |
stderr showCR:'<EOF>'. |
|
20833 | 1568 |
ex return. |
20774 | 1569 |
]. |
22764 | 1570 |
(stdout isOpen not) ifTrue:[ |
1571 |
stderr showCR:'no output'. |
|
20774 | 1572 |
]. |
22764 | 1573 |
(stderr isOpen not) ifTrue:[ |
20774 | 1574 |
]. |
1575 |
] do:[ |
|
22764 | 1576 |
stdin signalAtEnd:true. |
22743 | 1577 |
|
20774 | 1578 |
self |
22764 | 1579 |
basicReadEvalPrintLoopWithInput:stdin output:stdout error:stderr |
22762 | 1580 |
compiler:compilerClass prompt:true print:true. |
22743 | 1581 |
|
1582 |
]. |
|
20933 | 1583 |
]. |
20935 | 1584 |
"/ self errorStream showCR:('done.'). |
10463 | 1585 |
|
1586 |
" |
|
22764 | 1587 |
(ReadEvalPrintLoop new |
1588 |
doChunkFormat:false; |
|
1589 |
prompt:'>') readEvalPrintLoop |
|
1590 |
" |
|
1591 |
||
1592 |
" |
|
20933 | 1593 |
Stdin atEnd |
1594 |
Stdin clearEOF |
|
1595 |
Smalltalk readEvalPrintLoop |
|
10463 | 1596 |
(ReadEvalPrintLoop new prompt:'>') readEvalPrintLoop |
1597 |
" |
|
1598 |
||
1599 |
"Created: / 07-12-2006 / 17:27:21 / cg" |
|
20935 | 1600 |
"Modified: / 08-11-2016 / 22:42:21 / cg" |
10248 | 1601 |
! ! |
1602 |
||
16089 | 1603 |
!ReadEvalPrintLoop methodsFor:'queries'! |
1604 |
||
1605 |
autoDefineVariables |
|
1606 |
"when evaluating with --eval, auto define any variables" |
|
1607 |
||
1608 |
^ #workspace |
|
1609 |
! ! |
|
1610 |
||
10248 | 1611 |
!ReadEvalPrintLoop class methodsFor:'documentation'! |
1612 |
||
1613 |
version |
|
19379 | 1614 |
^ '$Header$' |
13121
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
1615 |
! |
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
1616 |
|
e0cc829d4b4d
added: #correctableError:position:to:from:
Claus Gittinger <cg@exept.de>
parents:
10635
diff
changeset
|
1617 |
version_CVS |
19379 | 1618 |
^ '$Header$' |
10248 | 1619 |
! ! |
19379 | 1620 |