[squeak-dev] Re: [Pharo-project] Prune stack serialization

Juan Vuletich juan at jvuletich.org
Sat Dec 3 02:01:45 UTC 2011


Eliot Miranda wrote:
>
>
> On Fri, Dec 2, 2011 at 4:01 PM, Juan Vuletich <juan at jvuletich.org 
> <mailto:juan at jvuletich.org>> wrote:
>
>     Eliot Miranda wrote:
>
>         Hi Juan,
>
>         ...
>
>
>
>            I can say that it does indeed work. But I'd be really
>         grateful if
>            Eliot took a good look at that code!
>
>
>         There is a much better way, using
>         InstructionStream>>interpreetNextInstructionFor: which
>         abstracts away from the bytecode encoding and allows one to
>         simply use messages.  e.g. look at
>
>         and (SortedCollection sortBlock: [:a :b| a compare: b
>         caseSensitive: false]) sortBlock abstractBytecodes evaluates to
>
>         an OrderedCollection(#pushTemporaryVariable:
>         #pushTemporaryVariable: #pushConstant: #send:super:numArgs:)
>
>         So a check for clean blocks would check for a block's
>         abstractBytecodes not including some particular set of banned
>         messages (which I *think* is pushReceiver
>         pushReceiverVariable: popIntoReceiverVariable:
>         storeIntoReceiverVariable: methodReturnConstant:
>         methodReturnReceiver methodReturnTop).
>
>         e.g.
>
>         isClean
>              ^(self abstractBytecodes intersection: #(pushReceiver
>         pushReceiverVariable: popIntoReceiverVariable:
>         storeIntoReceiverVariable: methodReturnConstant:
>         methodReturnReceiver methodReturnTop)) isEmpty
>
>
>            Cheers,
>            Juan Vuletich
>
>
>
>
>         -- 
>         best,
>         Eliot
>
>
>     Thanks Eliot. However, it looks to me that this needs more tweaking. 
>
>
> <blush>Damn right :)  I've done zero testing.  It was just an 
> example</blush>
>  
>
>     For instance, your method answers true for
>       [ xx size ] isClean
>     and
>       [ ^ nil ] isClean
>     while mine answers false for both. Maybe we could serialize non
>     local returns using the Compiler (although we won't be able to
>     return anywhere), but external variable acess is a problem.
>
>     Will keep playing with this for a while...
>
>
> Can you (can I??) write some tests?  What's xx in the above?  Ah! 
> [^nil] isn't clean in my code since it should be pc <= end, not pc < 
> end!!  Try the attached...

This is a start:

testIsClean
    "
    ClosureTests new testIsClean
    "
    | tempVar |
    tempVar := 1.
    self assert: [ 3 + 4 ] isClean.
    self assert: [ :a | a * 2 ] isClean.
    self assert: [ Smalltalk size ] isClean.
    self assert: [ :blockArg | blockArg printString ] isClean.
    self assert: [ | blockTemp | blockTemp printString ] isClean.
    self assert: [ | blockTemp | blockTemp :=7 ] isClean.
    self deny: [ | outerBlockTemp | [ outerBlockTemp printString ] 
isClean ] value.
    self deny: [ | outerBlockTemp | [ outerBlockTemp :=7 ] isClean ] value.
    self deny: [ tempVar + 1 ] isClean.
    self deny: [ tempVar := 1 ] isClean.
    self deny: [ ivar + 1 ] isClean.
    self deny: [ ivar := 1 ] isClean.
    self deny: [ ^ true ] isClean.
    self deny: [ self printString ] isClean.
    self deny: [ ^ self ] isClean.
    self deny: [ ClassVar + 1 ] isClean.
    self deny: [ ClassVar := 1 ] isClean.

This test passes with my implementation.

>  
>
>
>     Cheers,
>     Juan Vuletich
>
>
>
>
> -- 
> best,
> Eliot
>

Cheers,
Juan Vuletich



More information about the Squeak-dev mailing list