[squeak-dev] Swap operation for stack machinery?
Thiede, Christoph
Christoph.Thiede at student.hpi.uni-potsdam.de
Sun Feb 23 17:01:52 UTC 2020
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:<http://forum.world.st/Problems-with-caseError-tp5111930p5112251.html>. 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.
Best,
Christoph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200223/176aed5b/attachment.html>
More information about the Squeak-dev
mailing list
|