summaryrefslogtreecommitdiff
path: root/oryxc/src/sema
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2026-03-30 22:53:28 +0200
committerThomas Voss <mail@thomasvoss.com> 2026-03-30 22:53:28 +0200
commitbc548238b9dd1d15ddf0af8731d356a0ca6a61ad (patch)
treefce34d062211d1af1aa867253fae72bf26340ea5 /oryxc/src/sema
parent82ce31a7be9a67ea88c586c2792a7dcddd2a53d6 (diff)
Expand UnaryOperator and BinaryOperator
Diffstat (limited to 'oryxc/src/sema')
-rw-r--r--oryxc/src/sema/typecheck.rs63
1 files changed, 57 insertions, 6 deletions
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!(),
};