[squeak-dev] Swap operation for stack machinery?

Eliot Miranda eliot.miranda at gmail.com
Sun Feb 23 17:14:31 UTC 2020


Hi Christoph,

> 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.
> Looking forward to your answers.

Interesting! No, there’s no swap as yet. If SqueakV3PlusClosures has an unused bytecode I’d say go for it. (SistaV1 definitely has unused bytecodes).  But it’ll take a while got this to percolate through your protection VMs so make a fix not dependent on the swap bytecode as well.
> 
> Best,
> 
> Christoph
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200223/a4ff1c9c/attachment.html>


More information about the Squeak-dev mailing list