diff --git a/src/parsec.cpp b/src/parsec.cpp index a3c2456bb11a1dc7fa157cdef52cef6bb5e2c0d6..1d7c81af71454e33ea56aff645a1ad48bf9a957c 100644 --- a/src/parsec.cpp +++ b/src/parsec.cpp @@ -1099,8 +1099,17 @@ static AstNode *trans_binary_operator(Context *c, bool result_used, AstNode *blo emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_OrAssign"); return nullptr; case BO_Comma: - emit_warning(c, stmt->getLocStart(), "TODO handle more C binary operators: BO_Comma"); - return nullptr; + { + block = trans_create_node(c, NodeTypeBlock); + AstNode *lhs = trans_expr(c, false, block, stmt->getLHS(), TransRValue); + if (lhs == nullptr) return nullptr; + block->data.block.statements.append(maybe_suppress_result(c, false, lhs)); + AstNode *rhs = trans_expr(c, result_used, block, stmt->getRHS(), TransRValue); + if (rhs == nullptr) return nullptr; + block->data.block.statements.append(maybe_suppress_result(c, result_used, rhs)); + block->data.block.last_statement_is_result_expression = true; + return block; + } } zig_unreachable(); diff --git a/test/parsec.zig b/test/parsec.zig index c3f4ab5412a06312c345f7da7773f661a46a3818..c8e16755df9b7a62203f7176f5f3feb2cb275d0a 100644 --- a/test/parsec.zig +++ b/test/parsec.zig @@ -606,11 +606,23 @@ pub fn addCases(cases: &tests.ParseCContext) { \\ return null; \\} ); + + cases.addC("comma operator", + \\int foo(void) { + \\ return 1, 2; + \\} + , + \\export fn foo() -> c_int { + \\ return { + \\ _ = 1; + \\ 2 + \\ }; + \\} + ); } - // TODO //float *ptrcast(int *a) { // return (float *)a;