2 Little Smalltalk, Version 5
4 Copyright (C) 1987-2005 by Timothy A. Budd
5 Copyright (C) 2007 by Charles R. Childers
6 Copyright (C) 2005-2007 by Danny Reinhold
7 Copyright (C) 2010 by Ketmar // Vampire Avalon
9 ============================================================================
10 This license applies to the virtual machine and to the initial image of
11 the Little Smalltalk system and to all files in the Little Smalltalk
12 packages except the files explicitly licensed with another license(s).
13 ============================================================================
14 Permission is hereby granted, free of charge, to any person obtaining a copy
15 of this software and associated documentation files (the 'Software'), to deal
16 in the Software without restriction, including without limitation the rights
17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18 copies of the Software, and to permit persons to whom the Software is
19 furnished to do so, subject to the following conditions:
21 The above copyright notice and this permission notice shall be included in
22 all copies or substantial portions of the Software.
24 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 DEALINGS IN THE SOFTWARE.
33 Utility to interactively examine data structures"
35 Object subclass: Browser [
39 "Instantiate a browser on the named object"
44 "Display stack of objects we're inspecting"
46 ' == stack -> ' print.
49 (cnt > 0) ifTrue: [ ' / ' print ].
57 "Dump instance variables of named object"
59 iv <- obj class instanceVariables.
60 1 to: iv size do: [:idx|
61 idx print. Char tab print.
62 (iv at: idx) print. ': ' print.
63 (Object in: obj at: idx) printNl
68 "Compile and run Smalltalk expression on object"
70 "Assemble arguments into single String"
74 ifNotNil: [ t <- t + ' ' + arg ]
76 "Compile into xxBrowse Method for object's class"
78 t <- 'xxBrowse' + String newline + String tab + '^ ' + t.
79 (cl addMethod: t) ifNotNil: [
80 "Compile OK, run and print result"
82 "Now clean up (remove) browse method"
83 cl removeMethod: #xxBrowse
88 "Main UI loop for browser"
89 | cmd done last obj args idx |
90 stack <- Array with: top.
92 "Show where we are and get next command"
94 "Get next command, explode into cmd/args"
98 args <- cmd break: ' '.
100 args <- args from: 2.
101 "Get top of stack in its own variable"
102 obj <- stack at: (stack size).
105 ((cmd = 'i') or: [cmd = 'index']) ifTrue: [
106 last <- stack at: (stack size).
107 idx <- (args at: 1) asNumber.
108 last <- last at: idx.
112 "Nest to last displayed object"
113 ((cmd = 'n') or: [cmd = 'nest']) ifTrue: [
114 stack <- stack with: last.
118 ((cmd = 'c') or: [cmd = 'class']) ifTrue: [
122 "Pop up a stack level"
123 ((cmd = 'u') or: [cmd = 'up']) ifTrue: [
124 (stack size < 2) ifTrue: [
125 'Stack is empty' printNl
127 stack <- stack from: 1 to: (stack size - 1)
132 (cmd = 'ri') ifTrue: [
133 idx <- (args at: 1) asNumber.
134 last <- Object in: obj at: idx.
138 "List instance variables"
139 ((cmd = 'iv') or: [cmd = 'ivars']) ifTrue: [
144 ((cmd = 'bs') or: [cmd = 'bsize']) ifTrue: [
145 obj basicSize printNl.
148 ((cmd = 'sz') or: [cmd = 'size']) ifTrue: [
152 "Print arbitrary expression"
153 ((cmd = 'p') or: [cmd = 'print']) ifTrue: [
154 self run: args on: obj.
157 ((cmd = 'h') or: [cmd = 'help']) ifTrue: [
158 'browser commands' printNl.
159 '----------------' printNl.
160 'i index index with at:' printNl.
161 'n nest nest to last displayed object' printNl.
162 'c class show class' printNl.
163 'u up pop up a stack level' printNl.
164 'ri raw index' printNl.
165 'iv ivars list instance variables' printNl.
166 'bs bsize show size' printNl.
167 'sz size show size' printNl.
168 'p print print expression' printNl.
172 ((cmd = 'q') or: [cmd = 'quit']) ifTrue: [
176 done ifFalse: [ ('Unknown command: ' + cmd) printNl ]