diff --git a/a.out b/a.out new file mode 100755 index 0000000..6d37925 Binary files /dev/null and b/a.out differ diff --git a/builtin/builtin.c b/builtin/builtin.c index 5c9ab03..8557fb2 100644 --- a/builtin/builtin.c +++ b/builtin/builtin.c @@ -1,9 +1,10 @@ /* START builtins */ #include "stdio.h" +#include void _printf(char *msg) { printf(msg); } -/* END builtins */ \ No newline at end of file +/* END builtins */ diff --git a/examples/playground.sb b/examples/playground.sb index 584e33e..b88ca71 100644 --- a/examples/playground.sb +++ b/examples/playground.sb @@ -1,3 +1,11 @@ fn main(n: int) { _printf("Hello World!\n") + + if n > 2 { + _printf("Larger than 2\n") + } else if n == 2 { + _printf("Is 2\n") + } else { + _printf("Less than 2\n") + } } \ No newline at end of file diff --git a/src/generator/c.rs b/src/generator/c.rs index 04ea85c..9f846da 100644 --- a/src/generator/c.rs +++ b/src/generator/c.rs @@ -228,14 +228,14 @@ fn generate_bin_op(left: Expression, op: BinOp, right: Expression) -> String { BinOp::Addition => "+", BinOp::And => "&&", BinOp::Division => "/", - BinOp::Equal => "===", + BinOp::Equal => "==", BinOp::GreaterThan => ">", BinOp::GreaterThanOrEqual => ">=", BinOp::LessThan => "<", BinOp::LessThanOrEqual => "<=", BinOp::Modulus => "%", BinOp::Multiplication => "*", - BinOp::NotEqual => "!==", + BinOp::NotEqual => "!=", BinOp::Or => "||", BinOp::Subtraction => "-", }; diff --git a/src/parser/tests.rs b/src/parser/tests.rs index 46b31ed..60e6713 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -605,3 +605,18 @@ fn test_function_with_return_type() { assert!(tree.is_ok()); assert_eq!(tree.unwrap().func[0].ret_type, Some(Type::Int)); } + +#[test] +#[ignore] +fn test_booleans_in_function_call() { + let raw = " + if n > 2 { + _printf(true) + } else { + _printf(true) + } + "; + let tokens = tokenize(raw); + let tree = parse(tokens, Some(raw.to_string())); + assert!(tree.is_ok()); +}