[squeak-dev] Swap operation for stack machinery?

Eliot Miranda eliot.miranda at gmail.com
Sun Feb 23 17:19:34 UTC 2020



> On Feb 23, 2020, at 9:01 AM, Thiede, Christoph <Christoph.Thiede at student.hpi.uni-potsdam.de> wrote:
> 
> 
> Hi all,
> 
> 
> 
> I am curious to know whether the Squeak Context model provides any operation to swap the latest two elements from the stack. Something like:
> 
> 
> 
> doSwap
>     | first second |
>     first := self pop.
>     second := self pop.
>     self push: first.
>     self push: second.
> 
> If it exists, I could not find it yet. If it does not exist, would you see any need to implement it (for both VM & simulation, of course)?
> 
> 
> 
> To me, this appears to be the most performant approach to implement a parametrized #caseError:. Something like:
> 
> 
> 
> 81 <75> pushConstant: 0
> 82 <88> dup
> 83 <76> pushConstant: 1
> 84 <B6> send: =
> 85 <9A> jumpFalse: 89
> 86 <87> pop
> 87 <22> pushConstant: #one
> 88 <96> jumpTo: 97
> 89 <77> pushConstant: 2
> 90 <B6> send: =
> 91 <99> jumpFalse: 94
> 92 <21> pushConstant: #two
> 93 <91> jumpTo: 97
> 94 <70> self
> 95 <xx> swap
> 96 <D0> send: caseError:
> 97 <87> pop
> 
> Otherwise, we would need an extra temporary variable here.

BTW there is a horrible hack which avoids the extra temp.  Since the stack pointer and stack height are known during code generation then instead of this:

94 <70> self
95 <xx> swap
96 <D0> send: caseError:

one could emit this sequence:

    dup
    push self
    pop and store temp: N (where N gets to sp - 1)
    send caseError:

> Looking forward to your answers.
> 
> 
> Best,
> 
> Christoph
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200223/f31aa03d/attachment-0001.html>


More information about the Squeak-dev mailing list