Skip to content

i += 1 doesn't produce correct bytecode #46

@Synix4Life

Description

@Synix4Life

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions