wiz-lang / wiz

A high-level assembly language for writing homebrew software and games on retro console platforms.
http://wiz-lang.org/
Other
409 stars 40 forks source link

Cannot compile `ya = y * a;` on the SPC700 platform #145

Open undisbeliever opened 1 year ago

undisbeliever commented 1 year ago

While coding a SNES audio driver in wiz I noticed I was unable to compile a multiplication statement.

I made an attempt at fixing this bug, but I'm unsure how to fix it without adding a spc700 multiplication exception to Compiler::simplifyBinaryArithmeticExpression() or Compiler::reduceExpression().


// SYSTEM  spc700

bank code     @ 0x200 : [constdata; 0x100];

in code {

func test() {
    ya = y * a;
    ya = a * y;
}

}

Wiz output:

* wiz: version 0.1.2 (alpha)
>> Parsing...
>> Compiling...
mul_test.wiz:8: error: left-hand side of type `u16` cannot be assigned `u8` expression
mul_test.wiz:9: error: left-hand side of type `u16` cannot be assigned `u8` expression
* wiz: failed with 2 error(s).

I did discover a workaround, wrapping the multiplication in an inline func compiles successfully.

// SYSTEM  spc700

bank code     @ 0x200 : [constdata; 0x100];

in code {

inline func mul(u8a : u8 in a, u8y : u8 in y) : u16 in ya {
    return a * y;
}

func test() {
    ya = mul(a, y);
}

}