From a96a0cac034e16dcd7455a3b2fabf2b5b3e716bd Mon Sep 17 00:00:00 2001 From: Carlos Maniero Date: Wed, 10 May 2023 12:20:04 -0300 Subject: 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. --- examples/if.pipa | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'examples/if.pipa') 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; } -- cgit v1.2.3