[Vm-dev] Incomprehendable behaviour of ContextPart class
>>#contextOn:do:
Lars Wassermann
lars.wassermann at googlemail.com
Fri May 17 16:36:28 UTC 2013
Hello VM-dev,
I habe problems understanding what exactly happens when I step through:
(ContextPart contextOn: Error do: []) halt
in a workspace.
When I step over the parenthesis in the debugger, everything works kind
of like expected (the context of contextOn:do: misses one temporary but
the returned value is what the methods description promised). When I
step into or through the code, an error is raised when executing
bytecode 54 of #contextOn:do:, because the temps-array illegally has
been poped (by bytecode 53).
My question now is:
Why does the normal vm not only break when runing this code, but also
return the correct value (the first element of the last temporary).
I appended a graphic trying to visualize what happens up to the miracle
of three skipped bytecodes.
I replicated the behavior in Squeak 4.0 and 4.4 images on interpreter
VMs 3.7.7, 4.10, and a newer cog VM.
A fix to the problem of stepping and comprehension as well as the
missing temp in the frame would be changing the method to:
contextOn: exceptionClass do: block
"Create an #on:do: context that is ready to return from executing its
receiver"
| ctxt chain |
ctxt := thisContext.
[chain := thisContext sender cut: ctxt.
ctxt push: nil. ctxt jump] on: exceptionClass do: block.
"jump above will resume here without unwinding chain"
^ chain
The difference is that after cutting off ctxt, we ensure that it is a
top context by pushing a meaningless value. But this still doesn't help
me understanding the original behaviour.
Thank you and all the best
Lars
-------------- next part --------------
A non-text attachment was scrubbed...
Name: contextOn_do_.png
Type: image/png
Size: 65077 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20130517/712e39cd/contextOn_do_-0001.png
More information about the Vm-dev
mailing list