[Newbies] How to know where a BlockClosure finish
Mathieu
mathk.sue at gmail.com
Fri Aug 25 17:10:21 UTC 2006
Marcus Denker a écrit :
>
> On 25.08.2006, at 17:14, Mathieu wrote:
>
>> Hi,
>>
>> I want to execute several block:
>>
>> block1 value
>> block2 value
>> block3 value
>>
>> but if one block return from a retrun statement I want to quit.
>>
>> [^3] <- want to quit here
>> [3 + 4]
>>
>> So is there a way to know when a block evaluation finish by a return?
>>
>
> There is #hasMethodReturn in BlockContext:
>
> [^3] hasMethodReturn --> true
> [3] hasMethodReturn --> false.
>
> But this does a static analysis of the code... even if the ^is not executed
> (e.g.)
> [nil ifNotNil: [^3]] hasMethodReturn --> true
>
> so... it would be harder to analyze that dynamically... e.g. (without
> me thinking
> to much) you could add code (e.g. using ByteSurgeon)
> in front of the return inside a block to set a flag... but I have to
> admit that this
> woud be quite strange stuff...
>
>> I need this to interprete a file containing smalltalk and I want to
>> control the execution beceause I need to add some condition befor
>> evaluate a block.
>
> Why do you need that? I am sure we can find a simple solution if we
> understand
> the problem better.
>
> Marcus
>
>
Yes you are right
In the script I have 2 kind of things:
[
some Smalltalk
]
And:
Class selector
[
some smalltalk
]
So my idea was to call Compiler>>#evaluate:in:to:notifying:ifFail:logged:
on the string inside the [] for the first things.
And for the second I don't know yet but I don't think it's a probleme.
So I evaluate the "block" one by one. I don't think I can put them all
together beceause we can declare new method and use it in the next "block".
But may be I shouln't evaluate right now juste store them in a
CompiledMethod...
Math
More information about the Beginners
mailing list