["BUG"][FIX?]Incorrect Pseudo-Codefor#whileTrue:/#whileFalse:?
Stephan Rudlof
sr at evolgo.de
Sun Jan 7 19:09:38 UTC 2001
Dear Bob and Mark,
first I want to thank you for your interesting contributions!
After some playing with the debugger I think I have understood some of the
tricky issues.
But I prefer to prove my understanding:
Does
> > !BlockContext methodsFor: 'controlling' stamp: 'RAA 1/5/2001 23:10'!
> > repeatEndlessly
> > | loopAgain |
> > "Evaluate the receiver repeatedly, ending only if the block explicitly
> > returns."
> >
> > loopAgain _ thisContext pc.
> > self value.
> > thisContext jumpTo: loopAgain stack: 1.
> > self halt.
> > ! !
changed to
---
BlockContext>>
repeatEndlessly
| loopAgain |
"Evaluate the receiver repeatedly, ending only if the block
explicitly returns."
loopAgain _ thisContext realPc.
self value.
thisContext jumpTo: loopAgain.
self halt.
---
as bytecodes
---
17 <89> pushThisContext:
18 <D0> send: realPc
19 <68> popIntoTemp: 0
20 <70> self
21 <C9> send: value
22 <87> pop
23 <89> pushThisContext:
24 <10> pushTemp: 0
25 <E1> send: jumpTo:
26 <87> pop
27 <70> self
28 <D2> send: halt
29 <87> pop
30 <78> returnSelf
---
work now, since #jumpTo: as bytecodes
---
5 <10> pushTemp: 0
6 <81 01> storeIntoRcvr: 1
8 <7C> returnTop
---
results in moving loopAgain to the stack, what is expected by bytecode 19 in
#repeatEndlessly and results in assigning it to loopAgain again?
I know that it works, but I want to be sure that my explanation is
correct...
<snipped>
Given
---
BlockContext>>
repeatEndlesslyDangerous
| loopAgain |
"Evaluate the receiver repeatedly, ending only if the block
explicitly returns."
loopAgain _ thisContext pc.
self value.
thisContext jumpTo: loopAgain.
self halt.
---
and
---
BlockContext>>
whileTrue4Dangerous: aBlock
"
| x |
x _ 0.
[(x _ x + 1) < 100] whileTrue4Dangerous: [Transcript show: x printString;
cr].
"
[
self value ifFalse: [^self].
aBlock value.
] repeatEndlesslyDangerous
---
crashes if called by
---
| x |
self halt.
x _ 0.
[(x _ x + 1) < 100] whileTrue4Dangerous: [Transcript show: x printString;
cr].
---
with 'proceed'ing at the 'halt'.
But going into the debugger there carefully followed by 'step's and 'send's
with 'proceed'ing in
---
repeatEndlesslyDangerous
| loopAgain |
"Evaluate the receiver repeatedly, ending only if the block
explicitly returns."
loopAgain _ thisContext pc.
"proceed here with 'value' highlighted" self value.
thisContext jumpTo: loopAgain.
self halt.
---
at marked statement works.
Explanation: The VM takes an earlier bytecode for loopAgain as the debugger,
which results in a stack overflow by pushing thisContext (followed by
sending pc) again and again.
Is this correct?
Greetings,
Stephan
--
Stephan Rudlof (sr at evolgo.de)
"Genius doesn't work on an assembly line basis.
You can't simply say, 'Today I will be brilliant.'"
-- Kirk, "The Ultimate Computer", stardate 4731.3
More information about the Squeak-dev
mailing list
|