From bc548238b9dd1d15ddf0af8731d356a0ca6a61ad Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 30 Mar 2026 22:53:28 +0200 Subject: Expand UnaryOperator and BinaryOperator --- oryxc/src/sema/typecheck.rs | 63 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 6 deletions(-) (limited to 'oryxc/src/sema') diff --git a/oryxc/src/sema/typecheck.rs b/oryxc/src/sema/typecheck.rs index 27c3e31..5cb37c7 100644 --- a/oryxc/src/sema/typecheck.rs +++ b/oryxc/src/sema/typecheck.rs @@ -137,11 +137,9 @@ fn typecheck_expr( let ast = fdata.ast.get().unwrap(); let tokens = fdata.tokens.get().unwrap(); - const { - assert!(parser::NEXPRKINDS == 10, "Missing expression case"); - }; + const { assert!(parser::NEXPRKINDS == 36, "missing expression case") }; + let expr_type = match ast.nodes.kind()[node as usize] { - AstType::BinaryOperator => todo!(), AstType::Dereference => { let pointer = ast.nodes.sub()[node as usize].0; let ptype = typecheck_expr(c_state, fdata, pointer)?; @@ -165,8 +163,61 @@ fn typecheck_expr( let base = typecheck_expr(c_state, fdata, pointee)?; c_state.type_intr.intern(OryxType::Pointer { base }) }, - AstType::String => todo!(), - AstType::UnaryOperator => todo!(), + AstType::String => c_state.type_intr.intern(OryxType::UString), + + /* Unary ops */ + AstType::AddressOf => todo!(), + AstType::Pointer => todo!(), + AstType::UnaryComplement + | AstType::UnaryMinus + | AstType::UnaryNegate + | AstType::UnaryPlus => { + let rhs = ast.nodes.sub()[node as usize].0; + let base = typecheck_expr(c_state, fdata, rhs)?; + todo!("assert that type is numeric"); + base + }, + + /* Binary ops */ + AstType::BinaryEqual + | AstType::BinaryGreaterThan + | AstType::BinaryGreaterThanEqual + | AstType::BinaryLessThan + | AstType::BinaryLessThanEqual + | AstType::BinaryLogicalOr + | AstType::BinaryNotEqual => { + let SubNodes(lhs, rhs) = ast.nodes.sub()[node as usize]; + let ltype = typecheck_expr(c_state, fdata, lhs)?; + let rtype = typecheck_expr(c_state, fdata, rhs)?; + todo!("assert that types are boolean"); + }, + AstType::BinaryDivRem => { + let SubNodes(lhs, rhs) = ast.nodes.sub()[node as usize]; + let ltype = typecheck_expr(c_state, fdata, lhs)?; + let rtype = typecheck_expr(c_state, fdata, rhs)?; + todo!("assert that types are numeric"); + }, + AstType::BinaryAdd + | AstType::BinaryBitAnd + | AstType::BinaryBitAndNot + | AstType::BinaryBitOr + | AstType::BinaryBitXor + | AstType::BinaryDivide + | AstType::BinaryLeftRotate + | AstType::BinaryLeftShift + | AstType::BinaryLogicalAnd + | AstType::BinaryModulus + | AstType::BinaryMultiply + | AstType::BinaryRemainder + | AstType::BinaryRightRotate + | AstType::BinaryRightShift + | AstType::BinarySubtract => { + let SubNodes(lhs, rhs) = ast.nodes.sub()[node as usize]; + let ltype = typecheck_expr(c_state, fdata, lhs)?; + let rtype = typecheck_expr(c_state, fdata, rhs)?; + todo!("assert that types are numeric"); + }, + _ => unreachable!(), }; -- cgit v1.2.3