Let's rewrite the method this way:

attemptToAssign: value withIndex: index
        | process |
        "INSERT CODE HERE"
process := Processor activeProcess.
[ process suspendedContext: process suspendedContext sender ] fork.
Processor yield.
self error: 'should not be reached'.

This way it's clear that execution flow never reaches the end of the method
as the error message is never sent. For some reason in the previous code by
increasing the priority of the process the end of the method could be
reached, as Denis showed, which leaded to incorrect behavior. This is still
hackish and we still need to provide a better way of performing such
returns.

Any code can be written at the  "INSERT CODE HERE" position, including
exception signals, etc.

Normal methods ends with a return, for example, "^ self". When performed,
"^ self" pushes "self" on the sender's stack and resumes execution in the
sender. In this call-back, when reaching the end of the method, the
sender's execution needs to be resumed, but no value needs to be pushed on
its stack. That's why instead of a normal return I use:
process := Processor activeProcess.
[ process suspendedContext: process suspendedContext sender ] fork.
Processor yield.
I don't know how to explain it better. I understand that because it was
bugged it was very hard to understand. I will put a slice on the bug
tracker.



On Thu, Jan 26, 2017 at 10:35 AM, Clément Bera <bera.clem...@gmail.com>
wrote:

>
> *Sorry Clement, maybe I am stupid but it is not clear for me.*
>
> *If I put halt after "CAN'T REACH" I got debugger which means that it "can
> reach".*
> *Maybe by "CAN'T REACH" you mean that any return value will not be used?
> But it is not true: if I return something it will be result of original
> assignment expression. But as you said it could crash VM.*
>
> Ok I tried and I can see that. This is why I have bugs. Well "CAN'T REACH"
> was supposed to mean it cannot be reached, I don't understand how it could
> be reached.
>
>
> On Thu, Jan 26, 2017 at 10:18 AM, Denis Kudriashov <dionisi...@gmail.com>
> wrote:
>
>>
>> 2017-01-26 8:11 GMT+01:00 Clément Bera <bera.clem...@gmail.com>:
>>
>>> The "CAN'T REACH" comment is there because execution never reach that
>>> part of the code. If you write code there, it will never be executed. The
>>> process code performs a return without pushing any value on stack.
>>>
>>
>> Sorry Clement, maybe I am stupid but it is not clear for me.
>> If I put halt after "CAN'T REACH" I got debugger which means that it "can
>> reach".
>> Maybe by "CAN'T REACH" you mean that any return value will not be used?
>> But it is not true: if I return something it will be result of original
>> assignment expression. But as you said it could crash VM.
>>
>>
>>>
>>> Signalling an error is safe if the error is never resumed. But you'll
>>> need the returnNoValue for performance intensive modification tracking.
>>>
>>
>> Do you have reproducible test case to crash VM when #attemptToAssign is
>> badly implemented? It will help for framework implementation and would be
>> nice description for method. In comment we can point to it. Because this
>> magic with forking process is very confusing.
>> Also I not get your "returnNoValue" sentence.
>>
>
>

Reply via email to