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

Add bool/int casts, add bool comparison #126

Open Bananattack opened 3 years ago

Bananattack commented 3 years ago

Currently expressions of bool type are missing some useful things.

In particular, one cannot compare bools to each other. Comparisons currently only work on values of other types. Allow comparison for both equality, and ordered comparison. For order comparisons, it will define them as numeric comparisons by their equivalent integer representation (0 or 1). Comparisons such as == true and == false should be equivalent to a no-op and boolean not, respectively. Boolean equality is equivalent to exclusive nor, and boolean inequality is equivalent to exclusive or.

We also need to allow casting bools to integers and vice-versa. For casting a bool to integer, true maps to 1, false maps to 0. For casting an integer type to bool, non-zero is true, zero is false. Right now, the lack of bool casts means that users must make their own bool-like enums / let expressions, and potentially declare vars as u8 rather than their bool type.

For starters, only consider compile-time bool comparisons / casts. Later, we could look into conditionally loading 0 or 1 for expressions (probably in the manner as runtime ternary expressions will need to work). Expanding the runtime bool stuff gets messy because some bools are backed by u8 fields, others are actually a single bit in a flags register or something.