diff options
author | Carlos Maniero <carlos@maniero.me> | 2023-05-10 12:20:04 -0300 |
---|---|---|
committer | Carlos Maniero <carlos@maniero.me> | 2023-05-10 12:20:04 -0300 |
commit | a96a0cac034e16dcd7455a3b2fabf2b5b3e716bd (patch) | |
tree | fcd4d81007bba0dd934e136f78b195371e5f0326 /examples | |
parent | 88630ebbea03e85119cf9795320a83cb846bdd20 (diff) |
gas: Compile boolean variable assignment
When the assignment value is a literal, it just assigns zero or one to
the variable stack's location. If the value is an expression, it
compiles the expression and assign zeros and ones based on expression
result.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/if.pipa | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/examples/if.pipa b/examples/if.pipa index d65fc24..79f5724 100644 --- a/examples/if.pipa +++ b/examples/if.pipa @@ -1,6 +1,18 @@ fn main(): i32 { let n: i32 = 11; + let falsy: bool = false || n == 11 && n > 11; + let truth: bool = n + 1 > 11 && n - 1 < 11; + let literal_falsy: bool = false; + + if falsy { + return 201; + } + + if literal_falsy { + return 200; + } + if (n == 11) { if n != 12 { if n < 12 { @@ -15,7 +27,6 @@ fn main(): i32 { if false || false { return 199; } - if true || false { if false || true { if true && false { @@ -32,7 +43,10 @@ fn main(): i32 { if false || n >= 11 && n <= 11 { if false || false && false && false || true { if n + 1 > 11 && n - 1 < 11 { - return 42; + if truth { + return 42; + } + return 14; } return 13; } |