2 coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar)
3 Understanding is not required. Only obedience.
5 This program is free software. It comes without any warranty, to
6 the extent permitted by applicable law. You can redistribute it
7 and/or modify it under the terms of the Do What The Fuck You Want
8 To Public License, Version 2, as published by Sam Hocevar. See
9 http://sam.zoy.org/wtfpl/COPYING for more details.
20 ^newWith: blk descr: dsc [
21 ^(super new) initWith: blk descr: dsc
24 initWith: blk descr: dsc [
48 cmdList := Dictionary new.
56 add: cmd descr: descr handler: hand [
58 co := ReplCommand newWith: hand descr: descr.
59 cmdList at: cmd put: co.
64 args := cmdline break: (' \t').
65 args size < 1 ifTrue: [ ^nil ].
66 cmd := cmdList at: (args at: 1)
70 'avaliable commands:' printNl.
71 cmdList keysAndValuesDo: [ :key :value |
72 ' ' print. key print. String tab print.
77 'unknown command: ' print.
92 "initialize REPL commands"
93 clicmd := ReplCommands new.
102 descr: 'save current image and quit'
104 System loadModule: 'binimage'.
105 'writing "workimage.image"...' printNl.
106 args := File image: 'workimage.image'.
107 args print. ' objects written to image.' printNl.
111 descr: 'save current image'
113 System loadModule: 'binimage'.
114 'writing "workimage.image"...' printNl.
115 args := File image: 'workimage.image'.
116 args print. ' objects written to image.' printNl.
119 descr: 'save image w/o sources'
121 System loadModule: 'binimage'.
122 'writing "releaseimage.image"...' printNl.
123 args := File imageNoSources: 'releaseimage.image'.
124 args print. ' objects written to image.' printNl.
129 args size = 2 ifTrue: [
130 'loading file: ' print. (args at: 2) printNl.
131 File fileIn: (args at: 2).
133 ifFalse: [ 'ERROR: invalid number of arguments for ":l"' printNl. ].
138 args size = 2 ifTrue: [ System loadModule: (args at: 2). ]
139 ifFalse: [ 'ERROR: invalid number of arguments for ":m"' printNl. ].
142 descr: 'reload module'
144 args size = 2 ifTrue: [ System reloadModule: (args at: 2). ]
145 ifFalse: [ 'ERROR: invalid number of arguments for ":r"' printNl. ].
148 descr: 'show packages or package classes'
149 handler: [ :args :pkg |
150 args size = 1 ifTrue: [
151 Package packages keysDo: [:obj | obj asString printNl. ].
153 args size = 2 ifTrue: [
154 pkg := Package find: (args at: 2) asSymbol.
155 pkg ifNil: [ 'ERROR: invalid package name' printNl ]
157 pkg name asString printNl.
158 pkg classes do: [:obj |
159 (obj isKindOf: Class) ifTrue: [
160 obj isMeta ifFalse: [ ' ' print. obj asString printNl. ]
164 'ERROR: invalid number of arguments for ":p"' printNl.
169 descr: 'show class methods'
170 handler: [ :args :cls |
171 args size = 2 ifTrue: [
172 cls := globals at: ((args at: 2) asSymbol) ifAbsent: [ nil ].
173 ((cls notNil) and: [ cls isKindOf: Class ]) ifTrue: [
174 cls asString printNl.
175 cls class methods do: [:mth | ' ^' print. mth name asString printNl. ].
176 cls methods do: [:mth | ' ' print. mth name asString printNl. ].
179 'ERROR: invalid number of arguments for ":cm"' printNl.
183 descr: 'write package to Smalltalk source file'
184 handler: [ :args :fname :pkg |
185 args size > 1 ifTrue: [
186 System loadModule: 'pkgwrite'.
187 pkg := Package find: (args at: 2) asSymbol.
188 pkg ifNil: [ 'ERROR: invalid package name' printNl ]
190 args size > 2 ifTrue: [ fname := args at: 3 ]
191 ifFalse: [ fname := (pkg name asString) + '.st'. ].
192 'writing package ' print. pkg name asString print. ' to ' print. fname printNl.
193 (globals at: #PackageWriter) write: pkg name to: fname.
196 'ERROR: invalid number of arguments for ":PW"' printNl.
200 descr: 'disasm method; args: class method'
201 handler: [ :args :cls |
202 args size = 3 ifTrue: [
203 System loadModule: 'disasm'.
204 (args at: 2) print. '>>' print. (args at: 3) printNl.
205 cls := globals at: ((args at: 2) asSymbol) ifAbsent: [ nil ].
206 ((cls notNil) and: [ cls isKindOf: Class ]) ifTrue: [
207 (args at: 3) firstChar == $^ ifTrue: [
208 args at: 3 put: ((args at: 3) from: 2).
211 "cls disasmMethod: (args at: 3) asSymbol."
212 (cls := cls allMethods at: (args at: 3) asSymbol ifAbsent: [ nil ]) ifNil: [ 'no such method' printNl ]
213 ifNotNil: [ cls disassemble ].
216 'ERROR: invalid number of arguments for ":dis"' printNl.
220 obj commandsSet: clicmd.
233 "main execution loop"
236 System isStdInTTY ifTrue: [ '-> ' print ].
241 ifTrue: [ 'type ":h" to get some help or ":q" to quit' printNl ]
243 Case test: (cmd firstChar);
244 case: $: do: [ commands do: cmd ];
246 "create new global var"
247 cmd := (cmd from: 2) break: (' ' + String tab).
248 ((cmd size < 3) or: [ (cmd at: 2) ~= 'is' ] ) ifTrue: [ self error: 'invalid "=" command' ].
249 (res := cmd at: 1) isEmpty ifTrue: [ self error: 'empty var name in "="' ].
250 cmd := cmd removeFirst removeFirst.
251 s := ''. cmd do: [ :elem | s := s + elem + ' ' ].
253 globals at: res asSymbol put: s.
257 cmd removeTrailingBlanks lastChar == $. ifFalse: [ res printNl ].
264 "now hook '^new' method so REPL EP will get our new object"