felixangell / kpd

an old compiler for Krug written in D - a prototype version
MIT License
44 stars 1 forks source link

boolean operator codegen is incorrect #42

Closed felixangell closed 6 years ago

felixangell commented 6 years ago
func main() {
    let a = 3 > 5;
    let b = 5 > 3;
    if b > 1 {
        b = 32;
    }
    return a + b;
}

/// .stdout
/// 32

b > 1 evaluates to true even though b is equal to 1 and not greater than

felixangell commented 6 years ago

another case of this is

func main() {
    let a = 15;
    if a < 14 {
        a = 6;
    }
    if a <= 15 {
        a = 8;
    }
    if a < 50 {
        a = 9;
    }
    return a;
}

/// .stdout
/// 9

This gives us 8 and not 9. The same happens when checking a <= 50

felixangell commented 6 years ago
func main() {
    let j = 0;
    while j != 0 {
        j = j - 1;
    }
    return j;
}

/// .stdout
/// 0

Gives -1 and not 0

felixangell commented 6 years ago

Fixed!