[comp.lang.smalltalk] SmallTalk Methods - from Self Documenting to Cryptic

steiger@gemini.cs.nps.navy.mil (Robert Steigerwald) (03/26/91)

I am running MacSmalltalk, version 0.4.  Things were working fine until
one day my methods began converting to cryptic form.  Every time I "compile"
a method now, all comments in the method are deleted and all variable names
local to the method are changed to t1, t2, etc.  This is quite annoying and
the documentation says nothing.  What's  even more puzzling is that when I
re-install from the distribution disks, the problem persists.  Any ideas?

Bob Steigerwald

rick@cua.cary.ibm.com (Rick DeNatale) (03/26/91)

In article <1986@gemini.cs.nps.navy.mil> steiger@taurus.cs.nps.navy.mil () writes:
>I am running MacSmalltalk, version 0.4.  Things were working fine until
>one day my methods began converting to cryptic form.  Every time I "compile"
>a method now, all comments in the method are deleted and all variable names
>local to the method are changed to t1, t2, etc.  This is quite annoying and
>the documentation says nothing.  What's  even more puzzling is that when I
>re-install from the distribution disks, the problem persists.  Any ideas?
>
>Bob Steigerwald

This is just a guess, since it's been quite a while since I've used Apple   
ST-80, but it sounds like your change log isn't getting written when you	try to log a changed method.  I can't remember where Apple ST saves the changes,but for some reason (disk full, file size limit, resource file limit) I'd	guess that the write is failing.  

The reason that your methods look strange is that ST-80 decompiles the method
from bytecodes when the source isn't available.

Good Luck,
Rick DeNatale

sdl@lyra.mitre.org (Steven D. Litvinchouk) (03/27/91)

In article <1986@gemini.cs.nps.navy.mil> steiger@gemini.cs.nps.navy.mil (Robert Steigerwald) writes:

> I am running MacSmalltalk, version 0.4.  Things were working fine until
> one day my methods began converting to cryptic form.  Every time I "compile"
> a method now, all comments in the method are deleted and all variable names
> local to the method are changed to t1, t2, etc.  This is quite annoying and
> the documentation says nothing.  What's  even more puzzling is that when I
> re-install from the distribution disks, the problem persists.  Any ideas?

This has happened to me with other Smalltalks, when (for whatever
reason) Smalltalk is unable to find the source code of methods.  Then
it re-generates "source code" from the compiled code, inventing
temporary names (like t1, t2) for local variables.  I suggest you
check the installation and see where it looks for sources.


--
Steven Litvintchouk
MITRE Corporation
Burlington Road
Bedford, MA  01730
(617)271-7753
ARPA:  sdl@mbunix.mitre.org
UUCP:  ...{att,decvax,genrad,necntc,ll-xn,philabs,utzoo}!linus!sdl
	"Where does he get those wonderful toys?"

takamine@hpcc01.HP.COM (Derek Takamine) (03/27/91)

I believe you are experiencing a stuck 'left shift' hack syndrome.
If you look in CompiledCode>>getSourceForUserIfNone: method you'll
see a nifty peice of code that is great for intermittent debugging, 
among other uses.  I would guess that you had accidently hit your left
shit on your Mac keyboard while you clicked on a method in the 
Browser.  Now, for some unknown reason, it is always in that mode (maybe
it suposed to act like a toggle?) Try holding down the left shift key
again while clicking on a method.  

By the way, whats being displayed in your browser now is a text representation
of the compiled code.  This is how the byte code interpreter interprets
your method.  It's useful if you are trying to optimize performance of
your method.

huba@ls5.informatik.uni-dortmund.de (Hubert Baumeister) (03/28/91)

In article <1260003@hpcc01.HP.COM>, takamine@hpcc01.HP.COM (Derek Takamine) writes:
|> I believe you are experiencing a stuck 'left shift' hack syndrome.
|> If you look in CompiledCode>>getSourceForUserIfNone: method you'll
|> see a nifty peice of code that is great for intermittent debugging, 
|> among other uses.  I would guess that you had accidently hit your left
|> shit on your Mac keyboard while you clicked on a method in the 
|> Browser.  Now, for some unknown reason, it is always in that mode (maybe
|> it suposed to act like a toggle?) Try holding down the left shift key
|> again while clicking on a method.  

At least in Smalltalk-80 >= v2.2 left shift is not a toggle. The bytecodes
will be decompiled when you press the left shift key while selecting. This
is useful when your changes file is lost or when  your changes file is
corruped so that the pointers in the image point to wrong places in the
changes file. There is to my knowledge only one way to always display
the decompiled version of a  method, that is when SourcesFiles is nil.
If SourceFiles is not nil then selecting a method will result in an
notifier when SourcesFiles at: i is nil or points to a nonexistent  file.

|> 
|> By the way, whats being displayed in your browser now is a text representation
|> of the compiled code.  This is how the byte code interpreter interprets
|> your method.  It's useful if you are trying to optimize performance of
|> your method.

What's being displayed is the source code reconstructed from the bytecodes.
This restructed  code can be than again compiled.
In most cases this code looks  exactly as the original
source code, except for certain variable names and comments.
If you really want to see a symbolic representation of the bytecodes then use
(<Class> compiledMethodAt: <selector>) symbolic
e.g. for the method DocumentBrowser>rename you will get (Smalltalk-80 r4.0)
original:

rename
	"Rename the currently viewed document."

	| section title |
	self changeRequest ifFalse: [^self].
	section _ selection isNil
				ifTrue: [document]
				ifFalse: [selection].
	title _ DialogView request: 'new name' initialAnswer: section title copy.
	title = '' ifTrue: [^self].
	selection isNil
		ifTrue: 
			[document title: title.
			self changed: #windowLabel with: title]
		ifFalse: 
			[selection title: title.
			self changed: #document]


decompiled (left shift select)

rename
	| t1 t2 |
	self changeRequest ifFalse: [^self].
	t1 := selection isNil
				ifTrue: [document]
				ifFalse: [selection].
	(t2 := DialogView request: 'new name' initialAnswer: t1 title copy) = '' ifTrue: [^self].
	selection isNil
		ifTrue: 
			[document title: t2.
			self changed: #windowLabel with: t2]
		ifFalse: 
			[selection title: t2.
			self changed: #document].
	^self

Bytecode "assembler":
(DocumentBrowser compiledMethodAt: #rename) symbolic

 'normal CompiledMethod numArgs=0 numTemps=2 frameSize=12

literals: ({DialogView} ''new name'' #title #request:initialAnswer: '''' #title: #windowLabel #changed:with: #document )

1 <44> push self
2 <CE 88> non-immediate send changeRequest
4 <EC 01> jump true 7
6 <60> push self; return
7 <02> push inst 2
8 <AD> send isNil
9 <C1> jump false 12
10 <01> push inst 1
11 <6B> jump 13
12 <02> push inst 2
13 <4C> store local 0; pop
14 <34> push DialogView
15 <1D> push ''new name''
16 <10> push local 0
17 <72> send title
18 <F0 35> send copy
20 <93> send request:initialAnswer:
21 <4D> store local 1; pop
22 <11> push local 1
23 <20> push ''''
24 <A6> send =
25 <C0> jump false 27
26 <60> push self; return
27 <02> push inst 2
28 <AD> send isNil
29 <E8 0B> jump false 42
31 <01> push inst 1
32 <11> push local 1
33 <85> send title:
34 <45> pop; push self
35 <22> push #windowLabel
36 <11> push local 1
37 <CD 47> non-immediate send changed:with:
39 <66> pop
40 <E4 08> jump 50
42 <02> push inst 2
43 <11> push local 1
44 <85> send title:
45 <45> pop; push self
46 <24> push #document
47 <CE 3F> non-immediate send changed:
49 <66> pop
50 <60> push self; return
'

Hubert Baumeister
(huba@ls5.informatik.uni-dortmund.de)

takamine@hpcc01.HP.COM (Derek Takamine) (04/06/91)

Thanks for the correction! (Sorry for the mis info..)
Derek Takamine