aboutsummaryrefslogtreecommitdiff
path: root/src/type
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-05 12:08:23 +0300
committerJoel Kronqvist <joel.kronqvist@iki.fi>2025-08-05 12:08:23 +0300
commitbf458367d77cb4ca3f4ac0a4a8c9ffe13f71b09b (patch)
tree4019d2a46cf2c74dadd773aaa510a3867889a194 /src/type
parentc629fac4297b8f13bdab00100f3b05549174154e (diff)
downloadmyslip-bf458367d77cb4ca3f4ac0a4a8c9ffe13f71b09b.tar.gz
myslip-bf458367d77cb4ca3f4ac0a4a8c9ffe13f71b09b.zip
Implemented booleans (no if-else yet)
Diffstat (limited to 'src/type')
-rw-r--r--src/type/check.rs17
-rw-r--r--src/type/display.rs2
-rw-r--r--src/type/mod.rs2
3 files changed, 7 insertions, 14 deletions
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(());