instance of a block context from #mustBeBoolean (was: Re: source code of a block context)

Rob Withers reefedjib at yahoo.com
Thu Aug 11 02:50:41 UTC 2005


Hi,

I have a related question, that I have been recently struggling with.   
Short of removing the ifTrue:ifFalse: bytecodes from the VM and the 
compiler, I am trying to write a #mustBeBoolean method and find the 
boolean protocol sent (#ifTrue:) and the block.  Then I am going to 
resend it with #perform:with:.  I reached through the methodNode and 
got the selector.  I can't find the block argument, however.  Is it 
lost because the #mustBeBoolean overwrote the frame for #ifTrue:?  Can 
I re-instatiate it in the context of ctx?  Of course, there is no 
guarantee that that context is where the block was created.

Here's my method, so far:

mustBeBoolean
	| ctx msgNode sel |
	ctx := thisContext sender.
	msgNode := ctx methodNode block statements at: ctx stackPtr.
	sel := msgNode selector key.
	^ context
		redirectMessage: (MessageSend
		receiver: nil
		selector: sel
		arguments: (Array with: [])).

thank you,
Rob

On Aug 8, 2005, at 1:10 PM, Marcus Denker wrote:

>
> Am 08.08.2005 um 20:41 schrieb Houssam Fakih:
>
>> Hi all,
>>
>>
>> I’m looking for a method that extracts the source code of a block. 
>> For instance If I have the following blockContext: [^ self] I need a 
>> method that returns the following string: ‘^self’. Is there any 
>> method in Squeak that does this job or I have to write a new one?
> You could use the decompiler, so something like this:
>
> BlockContext>>printSource
>     ^String streamContents: [:str | self decompile printStatementsOn: 
> aStream indent: 0]
>
> But this would loose all comments and reformate the code... as it's 
> decompiled.
>
> Another thing you could do is to just use the decompiler to build up 
> the mapping from
> bytecode --> source. (aMethod methodNode sourceMap), and then copy the 
> string
> directly from the text using the offsets the encoder gives you.
>
> Overall: These parts of Squeak are really strange, it's very old stuff 
> that realy should
> be redone cleanly. If we would have a good meta-model, stuff like that 
> would be trivial
> to do.
>
>     Marcus




More information about the Squeak-dev mailing list