On 22 March 2011 23:20, Igor Stasenko <siguctua@gmail.com> wrote:
On 22 March 2011 19:43, Toon Verwaest <toon.verwaest@gmail.com> wrote:
It's a very simple idea really.
Where your bytecode would previously look like
pushTemp: 1 pushTemp: 2 add
now it looks like:
add 1, 2, 3
where 3 is the start of your original stack, for example.
So rather than pushing and popping etc, you just abstractly interpret the bytecodes and figure out the stack locations where they would be pushed. And then you use this number as arguments to a copy bytecode, rather than calling "push". This avoids having to maintain a stack where you up front already know what the target index will be. You know this up front since your code is static by itself.
The advantage is that you don't need to do stack-tricks to keep data around, since all the operation are simple things such as copy, loadFromOuterScope, storeInOuterScope, loadFromField, storeInField, ...
So conversely to what you might have thought beforehand, you don't have "real registers" around, you just consider a stackframe to be a set of registers. And you operate on them with easy bytecodes. The advantage, in addition to it being less work and thus slightly faster by itself, is that it will later on also map better on the real hardware. The operations already look like what normal assembler operations would look like.
So, as i understood , a code like:
someMethod
 | temp1 temp2 |
 ^ self send: temp1+temp2 with: temp2.
could be represented by following: (we need 5 temps on stack: )
1. temp1 2. temp2 3. receiver 4. - first arg for send 5. - second arg
bytecode:
1.storeSelf: 3 2. storeTemp: 1 to: 4 3. storeTemp: 2 to: 5 4. send #+ to: 4 5. storeTemp: 2 to: 5 6. send #send:with: to: 3 7. return: 3
(note here, that given bytecode already contains an optimization - a context slot #5 are not overridden by #+ send, the same argument temp2 is simply reused for subsequent send (#send:with:), which is quite nice).
oh... a little mistake i meant that instruction #5 could be optimized away, because slot #5 contents == temp2 are unchanged.
cheers, Toon
-- Best regards, Igor Stasenko AKA sig.
-- Best regards, Igor Stasenko AKA sig.