[Vm-dev] defensive error checking in a BlockContext environment for
[:n | n = 1 ifTrue: [1] ifFalse:[(factorial value: n-1) * n]]
gettimothy
gettimothy at zoho.com
Sun Dec 15 16:25:33 UTC 2013
Please shoot this down, if it is incorrect. (no details necessary, just a yes,no is sufficient)
In the discussion on the re-entrant problem for BlockContexts regarding this code:
| factorial |
factorial := [:n| n = 1 ifTrue: [1] ifFalse: [(factorial value: n - 1) * n]].
(1 to: 10) collect: factorial
This statement: "The block can’t be reentered without overwriting the sender field, preventing return to the first caller. "
Does not mean that the bock is reentered, the sender field is over-written and when we get to n=10 stage things go kablooie.
What happens is the coders detect this condition and the primitive code will not allow a sender to be over-written.
The error that is thrown is purposeful and defensive
I don't know what I am looking at yet, but I think that error check happens here:
Interpreter >> primitiveValueWithArgs
| argumentArray blockContext blockArgumentCount arrayArgumentCount initialIP |
argumentArray _ self popStack.
blockContext _ self popStack.
blockArgumentCount _ self argumentCountOfBlock: blockContext.
"If the argArray isnt actually an Array we ahve to unpop the above two"
(self isArray: argumentArray) ifFalse: [self unPop:2. ^self primitiveFail].
.....
Sound about right?
thx.
tty
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20131215/f1ac32d8/attachment.htm
More information about the Vm-dev
mailing list