From bf458367d77cb4ca3f4ac0a4a8c9ffe13f71b09b Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Tue, 5 Aug 2025 12:08:23 +0300 Subject: Implemented booleans (no if-else yet) --- src/type/check.rs | 17 +++++------------ src/type/display.rs | 2 +- src/type/mod.rs | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) (limited to 'src/type') diff --git a/src/type/check.rs b/src/type/check.rs index e9917c7..d678411 100644 --- a/src/type/check.rs +++ b/src/type/check.rs @@ -136,8 +136,7 @@ impl SExp { match self { Atom(Int(_)) => Ok(Integer), - Atom(True) => todo!(), - Atom(False) => todo!(), + Atom(True | False) => Ok(Boolean), Atom(Var(name)) => ctx.get(name) .ok_or(UndefinedVariable(name.to_string())) .cloned(), @@ -145,16 +144,10 @@ impl SExp { Atom(Mul) => Ok(arr(List(vec![Integer, Integer]), Integer)), // TODO varlen Atom(Sub) => Ok(arr(List(vec![Integer, Integer]), Integer)), Atom(Div) => Ok(arr(List(vec![Integer, Integer]), Integer)), - Atom(Eq) => todo!(), - Atom(Neq) => todo!(), - Atom(Lt) => todo!(), - Atom(Gt) => todo!(), - Atom(Le) => todo!(), - Atom(Ge) => todo!(), - Atom(Or) => todo!(), - Atom(And) => todo!(), - Atom(Xor) => todo!(), - Atom(Not) => todo!(), + Atom(Eq | Neq | Lt | Gt | Le | Ge) => + Ok(arr(List(vec![Integer, Integer]), Boolean)), + Atom(Or | And | Xor) => Ok(arr(List(vec![Boolean, Boolean]), Boolean)), + Atom(Not) => Ok(arr(Boolean, Boolean)), Atom(Nil) => Ok(List(vec![])), Atom(Quote) => Ok(arr( VarType("T".to_string()), diff --git a/src/type/display.rs b/src/type/display.rs index 832b289..3e4f49c 100644 --- a/src/type/display.rs +++ b/src/type/display.rs @@ -18,6 +18,7 @@ impl fmt::Display for Type { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Integer => write!(f, "{}", "Int"), + Boolean => write!(f, "{}", "Bool"), Arrow(a, b) => write!(f, "({} -> {})", a, b), List(types) => write!( f, @@ -28,7 +29,6 @@ impl fmt::Display for Type { .join(" ") ), VarType(name) => write!(f, "{}", name), - Boolean => todo!(), } } } diff --git a/src/type/mod.rs b/src/type/mod.rs index 8977d85..e4c0841 100644 --- a/src/type/mod.rs +++ b/src/type/mod.rs @@ -91,7 +91,7 @@ impl Type { pub fn is_concrete(&self) -> Result<(), String> { match self { Integer => Ok(()), - Boolean => todo!(), + Boolean => Ok(()), Arrow(a, b) => b.is_concrete().and_then(|_ok| a.is_concrete()), List(v) => { let mut res = Ok(()); -- cgit v1.2.3