commit 0827a8f36bd0b99b876586b8c7ee099fbc903535 (tree)
parent 4c8443d96db4a441b393ea0c3c8d76a7493f46d0
Author: Josh Wolfe <thejoshwolfe@gmail.com>
Date: Wed, 20 Sep 2017 21:47:43 -0700
==, !=
Diffstat:
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/parsec.cpp b/src/parsec.cpp
@@ -978,8 +978,7 @@ static AstNode *trans_binary_operator(Context *c, bool result_used, AstNode *blo
case BO_EQ:
return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeCmpEq, stmt->getRHS());
case BO_NE:
- emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_NE");
- return nullptr;
+ return trans_create_bin_op(c, block, stmt->getLHS(), BinOpTypeCmpNotEq, stmt->getRHS());
case BO_And:
emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_And");
return nullptr;
diff --git a/test/parsec.zig b/test/parsec.zig
@@ -373,6 +373,22 @@ pub fn addCases(cases: &tests.ParseCContext) {
\\}
);
+ cases.add("==, !=",
+ \\int max(int a, int b) {
+ \\ if (a == b)
+ \\ return a;
+ \\ if (a != b)
+ \\ return b;
+ \\ return a;
+ \\}
+ ,
+ \\export fn max(a: c_int, b: c_int) -> c_int {
+ \\ if (a == b) return a;
+ \\ if (a != b) return b;
+ \\ return a;
+ \\}
+ );
+
cases.add("logical and, logical or",
\\int max(int a, int b) {
\\ if (a < b || a == b)