--- a/ReadEvalPrintLoop.st Thu Dec 07 18:25:18 2006 +0100
+++ b/ReadEvalPrintLoop.st Thu Dec 07 19:07:27 2006 +0100
@@ -13,7 +13,7 @@
Object subclass:#ReadEvalPrintLoop
instanceVariableNames:'inputStream outputStream errorStream compiler prompt
- doChunkFormat'
+ doChunkFormat traceFlag timingFlag'
classVariableNames:''
poolDictionaries:''
category:'* uncategorized *'
@@ -69,6 +69,131 @@
prompt := something.
! !
+!ReadEvalPrintLoop methodsFor:'directives'!
+
+cmd_clear:lineStream
+ self cmd_setOrClear:lineStream to:false
+
+ "Created: / 07-12-2006 / 19:04:50 / cg"
+!
+
+cmd_exit:lineStream
+ Smalltalk exit
+
+ "Created: / 07-12-2006 / 18:55:46 / cg"
+!
+
+cmd_help:lineStream
+ errorStream
+ nextPutAll:
+'Everything entered up to an empty line is called a "chunk" and evaluated as a block.
+Lines starting with "#" are commands to the read-eval-print interpreter.
+
+Valid commands are:
+ help ............... this text
+ exit ............... exit smalltalk
+ use <package>....... use a package
+ stx:libwidg ........ GUI package
+ stx:libtool ........ IDE tool package
+ show <what> ........ show info
+ variables .......... interpreter variables
+ processes .......... processes
+ memory ............. memory usage
+ flags .............. flags
+ set/clear <flag> ... set or clear a flag
+ trace .............. tracing execution
+ timing ............. timing execution
+'
+
+ "Created: / 07-12-2006 / 18:54:20 / cg"
+!
+
+cmd_set:lineStream
+ self cmd_setOrClear:lineStream to:true
+
+ "Modified: / 07-12-2006 / 19:04:46 / cg"
+!
+
+cmd_setOrClear:lineStream to:aBoolean
+ |what|
+
+ lineStream skipSeparators.
+ what := lineStream nextAlphaNumericWord.
+ (what startsWith:'tra') ifTrue:[
+ traceFlag := aBoolean.
+ ^ self.
+ ].
+ (what startsWith:'tim') ifTrue:[
+ timingFlag := aBoolean.
+ ^ self.
+ ].
+
+ errorStream nextPutLine:'?? which flag ?'.
+
+ "Modified: / 07-12-2006 / 19:06:00 / cg"
+!
+
+cmd_show:lineStream
+ |what|
+
+ lineStream skipSeparators.
+ what := lineStream nextAlphaNumericWord.
+ (what startsWith:'var') ifTrue:[
+ ^ self.
+ ].
+ (what startsWith:'proc') ifTrue:[
+ MiniDebugger basicNew showProcesses.
+ ^ self.
+ ].
+ (what startsWith:'mem') ifTrue:[
+ errorStream nextPutAll:('overall: ',(ObjectMemory bytesUsed / 1024) printString,' kb').
+ errorStream nextPutAll:('free : ',(ObjectMemory freeSpace / 1024) printString,' kb').
+ errorStream nextPutAll:('minorGC: ',(ObjectMemory scavengeCount) printString).
+ errorStream nextPutAll:('majorGC: ',(ObjectMemory garbageCollectCount) printString).
+ ^ self.
+ ].
+ (what startsWith:'flag') ifTrue:[
+ errorStream nextPutAll:('trace : ',traceFlag printString).
+ errorStream nextPutAll:('timing: ',timingFlag printString).
+ ^ self.
+ ].
+
+ errorStream nextPutLine:'?? show what ?'.
+
+ "Modified: / 07-12-2006 / 19:06:31 / cg"
+!
+
+cmd_use:lineStream
+ |pkg|
+
+ lineStream skipSeparators.
+ pkg := lineStream upToEnd withoutSeparators.
+ Smalltalk loadPackage:pkg
+
+ "Created: / 07-12-2006 / 19:07:56 / cg"
+!
+
+directive:line
+ |s cmd|
+
+ s := line readStream.
+ s next. "/ skip the hash
+ s skipSeparators.
+
+ cmd := s nextAlphaNumericWord.
+ self
+ perform:('cmd_',cmd,':') asSymbol with:s
+ ifNotUnderstood:[
+ (errorStream ? Stderr)
+ nextPutAll:'?? invalid command: ';
+ nextPutAll:cmd;
+ nextPutAll:'. Type "#help" for help.';
+ cr.
+ ].
+
+ "Created: / 07-12-2006 / 18:49:17 / cg"
+! !
+
!ReadEvalPrintLoop methodsFor:'evaluation'!
readEvalPrintLoop
@@ -104,7 +229,9 @@
line := input nextLine.
line notEmptyOrNil ifTrue:[
- (line startsWith:'#') ifFalse:[
+ (line startsWith:'#') ifTrue:[
+ self directive:line
+ ] ifFalse:[
lines add:line.
]
].
@@ -131,10 +258,11 @@
"
"Created: / 07-12-2006 / 17:27:21 / cg"
+ "Modified: / 07-12-2006 / 18:45:44 / cg"
! !
!ReadEvalPrintLoop class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ReadEvalPrintLoop.st,v 1.5 2006-12-07 17:25:18 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ReadEvalPrintLoop.st,v 1.6 2006-12-07 18:07:27 cg Exp $'
! !