When using i+=1, it produces incorrect bytecode, whereas i = i + 1 produces correct bytecode.
Example:
Taking the Kong program:
fun make_i(): float{
var i: float = 0;
i += 1;
return i;
}
This produces the bytecode:
Function: make_i
$184 = LOAD_INT_CONSTANT 0 // i = 0
$183 = STORE_VARIABLE $184
$185 = LOAD_INT_CONSTANT 1
RETURN $183 // return i = 0 -> INCORRECT
But if we use i = i + 1; instead, the resulting bytecode is correct:
Function: make_i
$184 = LOAD_INT_CONSTANT 0 // i = 0
$183 = STORE_VARIABLE $184
$185 = LOAD_INT_CONSTANT 1
$186 = ADD $183, $185 // i = i + 1
$183 = STORE_VARIABLE $186
RETURN $183 // return i = 1 -> CORRECT
When using
i+=1, it produces incorrect bytecode, whereasi = i + 1produces correct bytecode.Example:
Taking the Kong program:
This produces the bytecode:
But if we use
i = i + 1;instead, the resulting bytecode is correct: