Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparing CArray and CString is accepted as valid code but leads to random results #153

Open
PtrMan opened this issue Dec 8, 2020 · 0 comments

Comments

@PtrMan
Copy link

PtrMan commented Dec 8, 2020

The compiler accepts comparison between a char CArray and a CString but it is not compiled/executed as a string comparison correctly! (results here are random).

struct Instr {
    var mnem: CArray[Char, 8]; // mnemonic of op
    var valF: Float32;
}

// interpret instruction
function interp(instr: Instr, stack: Ptr[Stack]) {
    if (instr.mnem) == "PUSHCF  " {
        stack.arr[stack.idx++] = instr.valF; // push
        printf("PUSH\n");
    }
    else if instr.mnem == "LININTER" {
        var intr = stack.arr[stack.idx--];
        var b = stack.arr[stack.idx--];
        var a = stack.arr[stack.idx--];
        
        stack.arr[stack.idx++] = a*(1.0-intr) + (b-a)*intr;
        printf("LININTER\n");
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant