wiz-lang / wiz

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

wiz allows an in block to exist inside a function #69

Open undisbeliever opened 5 years ago

undisbeliever commented 5 years ago

Wiz allows an in block to exist inside a function. Is this expected behaviour?

I can understand if the intention is for local variables like the example below, but the code below does not compile.

// SYSTEM  all

bank zeropage @ 0x0000 : [constdata;   0x100];
bank code     @ 0x8000 : [constdata;  0x8000];

in code {

// in statements are allowed inside in statements
in zeropage {
    var var0 : u8;
    var var1 : u8;
    var var2 : u8;
}

func f() {
    in zeropage {       // ERROR
        var var0 : u8;
        var var1 : u8;
        var var2 : u8;
    }
    a = var0;
    a = var1;
    a = var2;
}

}
--> ../bin/wiz --system 6502 -o obj/in_inside_func.6502.bin failure/in_inside_func.wiz
* wiz: version 0.1.2 (alpha)
>> Parsing...
>> Compiling...
failure/in_inside_func.wiz:17: error: local `var` declaration of `var0` must have an explicit address, or have a designated storage type
failure/in_inside_func.wiz:18: error: local `var` declaration of `var1` must have an explicit address, or have a designated storage type
failure/in_inside_func.wiz:19: error: local `var` declaration of `var2` must have an explicit address, or have a designated storage type
* wiz: failed with 3 error(s).
Bananattack commented 4 years ago

This is correct in reporting these variable declarations as erroneous. wiz needs a static keyword to declare non-local vars (will try to add), and local vars without designated storage or an explicit addresss are not supported yet (another task for stack frames). However, other usages of in { ... } blocks that can change the ROM bank should be forbidden.

I also wonder if the rules around in should change to allow entering multiple banks at the same time, and use the first bank compatible with the declaration. So eg. enter ROM + RAM bank in same in block and then the compiler will use one bank for code, the other for vars.

Edit: ugh hit submit while typing on phone, added more notes, bug should remain open!