2015-11-19 22:29 GMT+01:00 stepharo <stepharo@free.fr>:
SSA form?


and for method arguments?

foo: count
������ | sum |
������ sum := 0.
������ 1 to: count do: [ :ku | sum := sum + ku ].
������ ^ sum

transforms to:

��"foo: arg1
������ | tmp1 tmp2 |
������ tmp1 := 0.
������ tmp2 := arg1.
������ 1 to: tmp2 do: [ :tmp3 | tmp1 := tmp1 + tmp3 ].
������ ^ tmp1"


��
Le 19/11/15 22:14, Nicolai Hess a ��crit :

What is the purpose of replacing expressions, used as limits in a
to:do: call with by a new temporary variable?

For example:

OCOpalExamples>>#exampleToDoArgumentLimitIsExpression
the code is

exampleToDoArgumentLimitIsExpression
�� �� | count sum |
�� �� count := 10.
�� �� sum := 0.
�� �� 1 to: count - 1 do: [ :each | sum := sum + each].
�� �� ^sum

the decompiled bytecode :

exampleToDoArgumentLimitIsExpression
�� �� | tmp1 tmp2 tmp3 |
�� �� tmp1 := 10.
�� �� tmp2 := 0.
�� �� tmp3 := tmp1 - 1.
�� �� 1 to: tmp3 do: [ :tmp4 | tmp2 := tmp2 + tmp4 ].
�� �� ^ tmp2

So, the expression (count - 1) in the to:do: loop is replaced by a new
temporay (tmp3).

Ok, but why ?