350 showIt := self askYesNo:( |
350 showIt := self askYesNo:( |
351 'apropos: there are %1 matching %2; list them all (y/n)? ' |
351 'apropos: there are %1 matching %2; list them all (y/n)? ' |
352 bindWith:list size |
352 bindWith:list size |
353 with:listName) |
353 with:listName) |
354 ] ifFalse:[ |
354 ] ifFalse:[ |
355 self errorStream showCR:'matching %1:' with:listName. |
355 stderr showCR:'matching %1:' with:listName. |
356 ]. |
356 ]. |
357 showIt ifTrue:[ |
357 showIt ifTrue:[ |
358 sortedList := list asOrderedCollection sort. |
358 sortedList := list asOrderedCollection sort. |
359 longest := (list collect:[:nm | nm size]) max. |
359 longest := (list collect:[:nm | nm size]) max. |
360 limit := 78. |
360 limit := 78. |
361 numCols := (80 // (longest min:limit)) max:1. |
361 numCols := (80 // (longest min:limit)) max:1. |
362 colWidth := (longest min:limit). |
362 colWidth := (longest min:limit). |
363 sortedList slicesOf:numCols do:[:eachGroupOfN | |
363 sortedList slicesOf:numCols do:[:eachGroupOfN | |
364 self errorStream |
364 stderr |
365 spaces:2; |
365 spaces:2; |
366 nextPutLine:( |
366 nextPutLine:( |
367 (eachGroupOfN |
367 (eachGroupOfN |
368 collect:[:nm | |
368 collect:[:nm | |
369 (nm contractTo:colWidth) paddedTo:colWidth |
369 (nm contractTo:colWidth) paddedTo:colWidth |
544 ch isLetterOrDigit not and:[ch ~~ $_] |
542 ch isLetterOrDigit not and:[ch ~~ $_] |
545 ]. |
543 ]. |
546 "/ |
544 "/ |
547 (classOrMethodName isUppercaseFirst) ifTrue:[ |
545 (classOrMethodName isUppercaseFirst) ifTrue:[ |
548 (cls := Smalltalk classNamed:classOrMethodName) isNil ifTrue:[ |
546 (cls := Smalltalk classNamed:classOrMethodName) isNil ifTrue:[ |
549 errStream show:'edit: no such class: ',classOrMethodName,' ; create (y/n)? '. |
547 stderr show:'edit: no such class: ',classOrMethodName,' ; create (y/n)? '. |
550 (self inputStream nextLine withoutSeparators startsWith:'y') ifFalse:[^ self]. |
548 (self inputStream nextLine withoutSeparators startsWith:'y') ifFalse:[^ self]. |
551 isNewClass := true. |
549 isNewClass := true. |
552 code := |
550 code := |
553 '"/ change the code as required, then save and exit the editor. |
551 '"/ change the code as required, then save and exit the editor. |
554 "/ To cancel this edit, leave the editor WITHOUT saving. |
552 "/ To cancel this edit, leave the editor WITHOUT saving. |
578 ]. |
576 ]. |
579 |
577 |
580 isNewClass ifFalse:[ |
578 isNewClass ifFalse:[ |
581 cls := cls ? lastEditedClass. |
579 cls := cls ? lastEditedClass. |
582 cls isNil ifTrue:[ |
580 cls isNil ifTrue:[ |
583 errStream showCR:'edit usage:'. |
581 stderr showCR:'edit usage:'. |
584 errStream showCR:' #edit className selector'. |
582 stderr showCR:' #edit className selector'. |
585 errStream showCR:' #edit className '. |
583 stderr showCR:' #edit className '. |
586 errStream showCR:' #edit selector (class as in previous edit)'. |
584 stderr showCR:' #edit selector (class as in previous edit)'. |
587 errStream showCR:' #edit (class/method as in previous edit)'. |
585 stderr showCR:' #edit (class/method as in previous edit)'. |
588 ^ self. |
586 ^ self. |
589 ]. |
587 ]. |
590 lastEditedClass := cls. |
588 lastEditedClass := cls. |
591 lastEditedSelector := methodName. |
589 lastEditedSelector := methodName. |
592 |
590 |
638 onError:[:status | false]. |
636 onError:[:status | false]. |
639 |
637 |
640 (ok and:[tmpFile modificationTime ~= modifiedTime]) ifTrue:[ |
638 (ok and:[tmpFile modificationTime ~= modifiedTime]) ifTrue:[ |
641 isNewClass ifTrue:[ |
639 isNewClass ifTrue:[ |
642 Compiler evaluate:tmpFile contentsOfEntireFile. |
640 Compiler evaluate:tmpFile contentsOfEntireFile. |
643 errStream showCR:'Class (re)defined.' |
641 stderr showCR:'Class (re)defined.' |
644 ] ifFalse:[ |
642 ] ifFalse:[ |
645 editFullClass ifTrue:[ |
643 editFullClass ifTrue:[ |
646 tmpFile fileIn. |
644 tmpFile fileIn. |
647 errStream showCR:'Class (re)compiled.' |
645 stderr showCR:'Class (re)compiled.' |
648 ] ifFalse:[ |
646 ] ifFalse:[ |
649 cls compile:tmpFile contentsOfEntireFile classified:'*as yet uncategorized'. |
647 cls compile:tmpFile contentsOfEntireFile classified:'*as yet uncategorized'. |
650 errStream showCR:'Method (re)compiled.' |
648 stderr showCR:'Method (re)compiled.' |
651 ]. |
649 ]. |
652 ]. |
650 ]. |
653 ] ifFalse:[ |
651 ] ifFalse:[ |
654 errStream showCR:'No change.' |
652 stderr showCR:'No change.' |
655 ]. |
653 ]. |
656 ] ensure:[ |
654 ] ensure:[ |
657 tmpFile notNil ifTrue:[ |
655 tmpFile notNil ifTrue:[ |
658 tmpFile remove |
656 tmpFile remove |
659 ] |
657 ] |
758 lang = 'javascript' ifTrue:[ |
756 lang = 'javascript' ifTrue:[ |
759 compiler := JavaScriptCompiler. |
757 compiler := JavaScriptCompiler. |
760 ^ self. |
758 ^ self. |
761 ]. |
759 ]. |
762 |
760 |
763 self errorStream |
761 stderr |
764 showCR:'? usage: #language smalltalk'; |
762 showCR:'? usage: #language smalltalk'; |
765 showCR:'? or: #language javascript'. |
763 showCR:'? or: #language javascript'. |
766 ! |
764 ! |
767 |
765 |
768 cmd_list:lineStream |
766 cmd_list:lineStream |
769 "list directive; i.e. |
767 "list directive; i.e. |
770 #list <classname> ['class'] <selector> |
768 #list <classname> ['class'] <selector> |
771 " |
769 " |
772 |
770 |
773 |class selector source errStream| |
771 |class selector source| |
774 |
|
775 errStream := self errorStream. |
|
776 |
772 |
777 (self |
773 (self |
778 getClassNameAndSelectorFrom:lineStream |
774 getClassNameAndSelectorFrom:lineStream |
779 specialWords:nil |
775 specialWords:nil |
780 into:[:classArg :selectorArg | |
776 into:[:classArg :selectorArg | |
781 class := classArg. |
777 class := classArg. |
782 selector := selectorArg. |
778 selector := selectorArg. |
783 ]) ifFalse:[^ self]. |
779 ]) ifFalse:[^ self]. |
784 |
780 |
785 selector isNil ifTrue:[ |
781 selector isNil ifTrue:[ |
786 errStream nextPutAll:(class definition); cr. |
782 stderr nextPutAll:(class definition); cr. |
787 errStream nextPutAll:(class commentOrDocumentationString); cr. |
783 stderr nextPutAll:(class commentOrDocumentationString); cr. |
788 ] ifFalse:[ |
784 ] ifFalse:[ |
789 source := class sourceCodeAt:selector asSymbol. |
785 source := class sourceCodeAt:selector asSymbol. |
790 source isEmptyOrNil ifTrue:[ |
786 source isEmptyOrNil ifTrue:[ |
791 errStream nextPutLine:'Sorry, no sourcecode found' |
787 stderr nextPutLine:'Sorry, no sourcecode found' |
792 ] ifFalse:[ |
788 ] ifFalse:[ |
793 errStream nextPutAll:source; cr |
789 stderr nextPutAll:source; cr |
794 ]. |
790 ]. |
795 ]. |
791 ]. |
796 |
792 |
797 " |
793 " |
798 self basicNew |
794 self basicNew |
957 self answerPrompt:''. |
953 self answerPrompt:''. |
958 ]. |
954 ]. |
959 ^ self. |
955 ^ self. |
960 ]. |
956 ]. |
961 ]. |
957 ]. |
962 self errorStream |
958 stderr |
963 showCR:'? usage: set/clear <flag>'; |
959 showCR:'? usage: set/clear <flag>'; |
964 showCR:'? (<flag> must be one of: print, nodebug, confirmdebug, trace, times, profile, chunk, prompt, answerprompt, editor)'. |
960 showCR:'? (<flag> must be one of: print, nodebug, confirmdebug, trace, times, profile, chunk, prompt, answerprompt, editor)'. |
965 self cmd_show:('flags' readStream). |
961 self cmd_show:('flags' readStream). |
966 |
962 |
967 "Modified: / 08-11-2016 / 22:49:17 / cg" |
963 "Modified: / 08-11-2016 / 22:49:17 / cg" |
973 show modules (= loaded packages) |
969 show modules (= loaded packages) |
974 show variables |
970 show variables |
975 etc. |
971 etc. |
976 " |
972 " |
977 |
973 |
978 |errStream what showAll ok| |
974 |what showAll ok| |
979 |
|
980 errStream := self errorStream. |
|
981 |
975 |
982 lineStream skipSeparators. |
976 lineStream skipSeparators. |
983 what := lineStream nextAlphaNumericWord. |
977 what := lineStream nextAlphaNumericWord. |
984 ok := false. |
978 ok := false. |
985 |
979 |
986 what notNil ifTrue:[ |
980 what notNil ifTrue:[ |
987 showAll := (what startsWith:'all'). |
981 showAll := (what startsWith:'all'). |
988 |
982 |
989 (showAll or:[ what startsWith:'var' ]) ifTrue:[ |
983 (showAll or:[ what startsWith:'var' ]) ifTrue:[ |
990 errStream showCR:'Variables:'; showCR:'----------'. |
984 stderr showCR:'Variables:'; showCR:'----------'. |
991 self showVariables. |
985 self showVariables. |
992 ok := true. |
986 ok := true. |
993 ]. |
987 ]. |
994 |
988 |
995 (showAll or:[ what startsWith:'proc' ]) ifTrue:[ |
989 (showAll or:[ what startsWith:'proc' ]) ifTrue:[ |
996 errStream cr; showCR:'Threads:'; showCR:'--------'. |
990 stderr cr; showCR:'Threads:'; showCR:'--------'. |
997 MiniDebugger basicNew showProcesses. |
991 MiniDebugger basicNew showProcesses. |
998 ok := true. |
992 ok := true. |
999 ]. |
993 ]. |
1000 |
994 |
1001 ("showAll or:[" what startsWith:'pack' "]") ifTrue:[ |
995 ("showAll or:[" what startsWith:'pack' "]") ifTrue:[ |
1002 errStream cr; showCR:'Available Packages:'; showCR:'--------'. |
996 stderr cr; showCR:'Available Packages:'; showCR:'--------'. |
1003 self showPackages. |
997 self showPackages. |
1004 ok := true. |
998 ok := true. |
1005 ]. |
999 ]. |
1006 |
1000 |
1007 (showAll or:[ what startsWith:'mod' ]) ifTrue:[ |
1001 (showAll or:[ what startsWith:'mod' ]) ifTrue:[ |
1008 errStream cr; showCR:'Modules:'; showCR:'--------'. |
1002 stderr cr; showCR:'Modules:'; showCR:'--------'. |
1009 self showModules. |
1003 self showModules. |
1010 |
1004 |
1011 ok := true. |
1005 ok := true. |
1012 ]. |
1006 ]. |
1013 |
1007 |
1014 (showAll or:[ what startsWith:'mem' ]) ifTrue:[ |
1008 (showAll or:[ what startsWith:'mem' ]) ifTrue:[ |
1015 |allMem| |
1009 |allMem| |
1016 |
1010 |
1017 errStream cr; showCR:'Memory:'; showCR:'-------'. |
1011 stderr cr; showCR:'Memory:'; showCR:'-------'. |
1018 "/ allMem := ObjectMemory oldSpaceUsed + ObjectMemory symSpaceUsed |
1012 "/ allMem := ObjectMemory oldSpaceUsed + ObjectMemory symSpaceUsed |
1019 "/ + ObjectMemory newSpaceUsed. |
1013 "/ + ObjectMemory newSpaceUsed. |
1020 errStream |
1014 stderr |
1021 "/ showCR:('overall: ',(allMem // 1024) printString,' Kb'); |
1015 "/ showCR:('overall: ',(allMem // 1024) printString,' Kb'); |
1022 showCR:('used : ',(ObjectMemory bytesUsed // 1024) printString,' Kb'); |
1016 showCR:('used : ',(ObjectMemory bytesUsed // 1024) printString,' Kb'); |
1023 showCR:('free : ',(ObjectMemory freeSpace // 1024) printString,' Kb'); |
1017 showCR:('free : ',(ObjectMemory freeSpace // 1024) printString,' Kb'); |
1024 show:('minorGC: ',(ObjectMemory scavengeCount) printString); |
1018 show:('minorGC: ',(ObjectMemory scavengeCount) printString); |
1025 showCR:(' majorGC: ',(ObjectMemory garbageCollectCount) printString). |
1019 showCR:(' majorGC: ',(ObjectMemory garbageCollectCount) printString). |
1026 ok := true. |
1020 ok := true. |
1027 ]. |
1021 ]. |
1028 |
1022 |
1029 (showAll or:[ what startsWith:'flag' ]) ifTrue:[ |
1023 (showAll or:[ what startsWith:'flag' ]) ifTrue:[ |
1030 errStream cr; showCR:'Flags:'; showCR:'------'. |
1024 stderr cr; showCR:'Flags:'; showCR:'------'. |
1031 errStream |
1025 stderr |
1032 showCR:('print: ',self printFlag printString); |
1026 showCR:('print: ',self printFlag printString); |
1033 showCR:('nodebug: ',self noDebugger printString); |
1027 showCR:('nodebug: ',self noDebugger printString); |
1034 showCR:('confirmdebug:',self confirmDebugger printString); |
1028 showCR:('confirmdebug:',self confirmDebugger printString); |
1035 showCR:('trace : ',(traceFlag ? false) printString); |
1029 showCR:('trace : ',(traceFlag ? false) printString); |
1036 showCR:('timing: ',(timingFlag ? false) printString); |
1030 showCR:('timing: ',(timingFlag ? false) printString); |
1085 [ |
1079 [ |
1086 Smalltalk loadPackage:pkg. |
1080 Smalltalk loadPackage:pkg. |
1087 ] on:PackageLoadError do:[:ex| |
1081 ] on:PackageLoadError do:[:ex| |
1088 "/ allow for some shortcuts... |
1082 "/ allow for some shortcuts... |
1089 (pkg includes:$:) ifTrue:[ |
1083 (pkg includes:$:) ifTrue:[ |
1090 self errorStream showCR:('Failed to load package: "',pkg,'"'). |
1084 stderr showCR:('Failed to load package: "',pkg,'"'). |
1091 ] ifFalse:[ |
1085 ] ifFalse:[ |
1092 "/ try stx standard package |
1086 "/ try stx standard package |
1093 pkg := (self defaultPackagePrefix), pkg. |
1087 pkg := (self defaultPackagePrefix), pkg. |
1094 ex restart. |
1088 ex restart. |
1095 ]. |
1089 ]. |
1110 s skipSeparators. |
1104 s skipSeparators. |
1111 |
1105 |
1112 cmd := s nextAlphaNumericWord. |
1106 cmd := s nextAlphaNumericWord. |
1113 cmd notNil ifTrue:[ |
1107 cmd notNil ifTrue:[ |
1114 AbortAllOperationRequest handle:[:ex | |
1108 AbortAllOperationRequest handle:[:ex | |
1115 self errorStream showCR:('Directive aborted: ', ex description) |
1109 stderr showCR:('Directive aborted: ', ex description) |
1116 ] do:[ |
1110 ] do:[ |
1117 Error handle:[:ex | |
1111 Error handle:[:ex | |
1118 self errorStream showCR:('Caught in directive: ', ex description). |
1112 stderr showCR:('Caught in directive: ', ex description). |
1119 ex suspendedContext fullPrintAll. |
1113 ex suspendedContext fullPrintAll. |
1120 ] do:[ |
1114 ] do:[ |
1121 ControlInterrupt handle:[:ex | |
1115 ControlInterrupt handle:[:ex | |
1122 MiniDebugger enter. |
1116 MiniDebugger enter. |
1123 "/ self errorStream showCR:('Ignored in directive: ', ex description). |
1117 "/ stderr showCR:('Ignored in directive: ', ex description). |
1124 "/ ex reject. |
1118 "/ ex reject. |
1125 "/ ex proceed. |
1119 "/ ex proceed. |
1126 ] do:[ |
1120 ] do:[ |
1127 self |
1121 self |
1128 perform:('cmd_',cmd) asMutator with:s |
1122 perform:('cmd_',cmd) asMutator with:s |
1129 ifNotUnderstood:[ |
1123 ifNotUnderstood:[ |
1130 self errorStream |
1124 stderr |
1131 showCR:'?? invalid command: %1. Type "#help" for help.' with:cmd. |
1125 showCR:'?? invalid command: %1. Type "#help" for help.' with:cmd. |
1132 ]. |
1126 ]. |
1133 ]. |
1127 ]. |
1134 ]. |
1128 ]. |
1135 ]. |
1129 ]. |
1178 aBlock value:class value:selector. |
1172 aBlock value:class value:selector. |
1179 ^ true |
1173 ^ true |
1180 ! |
1174 ! |
1181 |
1175 |
1182 showModules |
1176 showModules |
1183 |errStream printModule| |
1177 |printModule| |
1184 |
1178 |
1185 errStream := self errorStream. |
|
1186 |
|
1187 printModule := |
1179 printModule := |
1188 [:mod | |
1180 [:mod | |
1189 errStream |
1181 stderr |
1190 show:' '; |
1182 show:' '; |
1191 show:(mod package "libraryName"); |
1183 show:(mod package "libraryName"); |
1192 showCR:' (',(mod type),')'. |
1184 showCR:' (',(mod type),')'. |
1193 ]. |
1185 ]. |
1194 |
1186 |
1195 errStream nextPutLine:'builtIn:'. |
1187 stderr nextPutLine:'builtIn:'. |
1196 ((ObjectMemory binaryModuleInfo |
1188 ((ObjectMemory binaryModuleInfo |
1197 reject:[:m | m dynamic]) |
1189 reject:[:m | m dynamic]) |
1198 asSortedCollection:[:a :b | a name < b name]) do:printModule. |
1190 asSortedCollection:[:a :b | a name < b name]) do:printModule. |
1199 |
1191 |
1200 errStream nextPutLine:'dynamic:'. |
1192 stderr nextPutLine:'dynamic:'. |
1201 ((ObjectMemory binaryModuleInfo |
1193 ((ObjectMemory binaryModuleInfo |
1202 select:[:m | m dynamic]) |
1194 select:[:m | m dynamic]) |
1203 asSortedCollection:[:a :b | a name < b name]) do:printModule. |
1195 asSortedCollection:[:a :b | a name < b name]) do:printModule. |
1204 |
1196 |
1205 " |
1197 " |
1214 Smalltalk knownLoadablePackagesDo:[:packageID :type :path | |
1206 Smalltalk knownLoadablePackagesDo:[:packageID :type :path | |
1215 all add:packageID |
1207 all add:packageID |
1216 ]. |
1208 ]. |
1217 all := all asOrderedCollection sort. |
1209 all := all asOrderedCollection sort. |
1218 all do:[:eachPackage | |
1210 all do:[:eachPackage | |
1219 self errorStream show:eachPackage. |
1211 stderr show:eachPackage. |
1220 (Smalltalk isPackageLoaded:eachPackage) ifTrue:[ |
1212 (Smalltalk isPackageLoaded:eachPackage) ifTrue:[ |
1221 self errorStream show:' (loaded)'. |
1213 stderr show:' (loaded)'. |
1222 ]. |
1214 ]. |
1223 self errorStream cr. |
1215 stderr cr. |
1224 ]. |
1216 ]. |
1225 |
1217 |
1226 " |
1218 " |
1227 ReadEvalPrintLoop basicNew showPackages |
1219 ReadEvalPrintLoop basicNew showPackages |
1228 ReadEvalPrintLoop basicNew showModules |
1220 ReadEvalPrintLoop basicNew showModules |