diff options
author | Carlos Maniero <carlos@maniero.me> | 2023-05-10 00:20:00 -0300 |
---|---|---|
committer | Carlos Maniero <carlos@maniero.me> | 2023-05-10 12:15:01 -0300 |
commit | 5de2e1fd9f426348127a66d2c51c300cb90cc3a4 (patch) | |
tree | 4dfa61999777227ca35a4d9d092f41996af6d26e /examples/if.pipa | |
parent | ad54ee1182b1549880eddc8b1969d3992d9f7f1d (diff) |
gas: Generate code for if statement
If statements are now working, the only exception is for the comparators
|| and && that will be addressed in a further commit. Checks tested:
fn main(): i32 {
let n: i32 = 11;
if (n == 11) {
if n != 12 {
if n < 12 {
if n <= 11 {
if n > 10 {
if n >= 11 {
return 42;
}
}
}
}
}
}
return n;
}
To compile the && and || a precedence issue must be addressed: they must
have the highest precedence, witch is not working now:
1 == 2 || 3 != 2
The or should be the higher level of the tree in the example above.
Signed-off-by: Carlos Maniero <carlos@maniero.me>
Diffstat (limited to 'examples/if.pipa')
-rw-r--r-- | examples/if.pipa | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/examples/if.pipa b/examples/if.pipa index 2c5578d..b7cadcb 100644 --- a/examples/if.pipa +++ b/examples/if.pipa @@ -1,8 +1,18 @@ fn main(): i32 { - let n: i32 = 42; + let n: i32 = 11; - if n > 42 { - return 42; + if (n == 11) { + if n != 12 { + if n < 12 { + if n <= 11 { + if n > 10 { + if n >= 11 { + return 42; + } + } + } + } + } } return n; |