diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-14 15:31:27 +0300 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-14 15:31:27 +0300 |
commit | 928a3358483f60db84dc2918415882b35adc006b (patch) | |
tree | 0b35b8e601f3ca93cdeb7f8d45bb1d06cf274e66 | |
parent | 907bd54d19f6bf14a130a136df6f37cc5d256468 (diff) | |
download | myslip-928a3358483f60db84dc2918415882b35adc006b.tar.gz myslip-928a3358483f60db84dc2918415882b35adc006b.zip |
fix: removed obsolete code for handling types as they are now parsed directly to atoms
-rw-r--r-- | src/parse/parsetree.rs | 3 | ||||
-rw-r--r-- | src/sexp/display.rs | 1 | ||||
-rw-r--r-- | src/sexp/mod.rs | 1 | ||||
-rw-r--r-- | src/sexp/step.rs | 28 | ||||
-rw-r--r-- | src/type/check.rs | 3 | ||||
-rw-r--r-- | src/type/display.rs | 22 | ||||
-rw-r--r-- | src/type/util.rs | 8 |
7 files changed, 16 insertions, 50 deletions
diff --git a/src/parse/parsetree.rs b/src/parse/parsetree.rs index 701496b..0a5782d 100644 --- a/src/parse/parsetree.rs +++ b/src/parse/parsetree.rs @@ -123,9 +123,6 @@ fn tokens_to_ast_inner( Some(Sym(s)) if s == "let" => Ok(Atom(Let)), Some(Sym(s)) if s == "fn" => Ok(Atom(Fun)), Some(Sym(s)) if s == "case" => Ok(Atom(Case)), - Some(Sym(s)) if s == "->" => Ok(Atom(Arr)), - Some(Sym(s)) if s == "int" => Ok(Atom(Ty(Integer))), - Some(Sym(s)) if s == "bool" => Ok(Atom(Ty(Boolean))), Some(Sym(s)) if s.starts_with("..") => Ok(Atom(RestPat(s.strip_prefix("..").unwrap().to_string()))), Some(Sym(s)) => Ok(Atom(Var(s))), diff --git a/src/sexp/display.rs b/src/sexp/display.rs index 9f54efe..ceab833 100644 --- a/src/sexp/display.rs +++ b/src/sexp/display.rs @@ -33,7 +33,6 @@ impl fmt::Display for SLeaf { Fun => "fn".to_string(), Case => "case".to_string(), Ty(t) => t.to_string(), - Arr => "->".to_string(), Nil => "()".to_string(), }) } diff --git a/src/sexp/mod.rs b/src/sexp/mod.rs index ba8743f..eeeb2d6 100644 --- a/src/sexp/mod.rs +++ b/src/sexp/mod.rs @@ -41,7 +41,6 @@ pub enum SLeaf { Case, Ty(Type), - Arr, Print, diff --git a/src/sexp/step.rs b/src/sexp/step.rs index d35c8af..5b60fec 100644 --- a/src/sexp/step.rs +++ b/src/sexp/step.rs @@ -323,29 +323,12 @@ impl SExp { pub fn step(self) -> Result<Self, String> { match self { - - // Type list (maybe these should just be parsed...) - SCons(op, l) if (*op).is_type_lit() => { - if *l == Atom(Nil) { - return Ok(*op); - } - let mut res = vec![]; - for exp in std::iter::once(*op).chain(l.parts()) { - res.push(match exp.multistep()? { - Atom(Ty(t)) => Ok(t), - e => Err(format!("not a type: {e}")), - }?); - } - Ok(Atom(Ty(List(res)))) - }, - // t is value // ---------- // t -> t t if t.is_value() => Ok(t), - // List processing // op not a value @@ -633,17 +616,6 @@ impl SExp { } }, - // Type arrow - SCons(op, l) if *op == Atom(Arr) => { - let ls = l.parts(); - let t1 = ls.get(0).ok_or("wrong list length".to_string())?; - let t2 = ls.get(1).ok_or("wrong list length".to_string())?; - match (t1.clone().multistep()?, t2.clone().multistep()?) { - (Atom(Ty(a)), Atom(Ty(b))) => Ok(Atom(Ty(arr(a.clone(), b.clone())))), - _ => Err("invalid args".to_string()), - } - }, - // Nil in list SCons(op, _) if *op == Atom(Nil) => { Ok(scons(Vector, Nil)) diff --git a/src/type/check.rs b/src/type/check.rs index 69e9141..ad6be13 100644 --- a/src/type/check.rs +++ b/src/type/check.rs @@ -127,7 +127,7 @@ impl SExp { /// }; /// /// let varlist = scons(var("a"), scons(var("b"), Nil)); - /// let typelist = scons(Ty(Integer), scons(Ty(Integer), Nil)); + /// let typelist = scons(Ty(List(vec![Integer])), Nil); /// let ret = Atom(Ty(Boolean)); /// let body = scons(Eq, varlist.clone()); /// assert_eq!( @@ -256,7 +256,6 @@ impl SExp { Atom(Let) => Ok(LetType), Atom(Print) => Ok(arr(vt("_"), List(vec![]))), Atom(Ty(_)) => Ok(TypeLit), - Atom(Arr) => Ok(arr(List(vec![TypeLit, TypeLit]), TypeLit)), Atom(Fun) => Err(FunAsAtom), Atom(Case) => Err(CaseAsAtom), Atom(RestPat(_)) => Err(RestAsAtom), diff --git a/src/type/display.rs b/src/type/display.rs index 56b22b6..27f1427 100644 --- a/src/type/display.rs +++ b/src/type/display.rs @@ -19,21 +19,21 @@ impl fmt::Display for Type { /// Examples: /// ```rust /// use myslip::r#type::{Type::*, util::*}; - /// assert_eq!(Integer.to_string(), "int".to_string()); - /// assert_eq!(Boolean.to_string(), "bool".to_string()); - /// assert_eq!(arr(Integer, Boolean).to_string(), "(int -> bool)".to_string()); - /// assert_eq!(List(vec![Integer, Boolean, Integer]).to_string(), "(int bool int)".to_string()); + /// assert_eq!(Integer.to_string(), "Int".to_string()); + /// assert_eq!(Boolean.to_string(), "Bool".to_string()); + /// assert_eq!(arr(Integer, Boolean).to_string(), "(Int -> Bool)".to_string()); + /// assert_eq!(List(vec![Integer, Boolean, Integer]).to_string(), "(Int Bool Int)".to_string()); /// ``` fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Integer => write!(f, "{}", "int"), - Boolean => write!(f, "{}", "bool"), + Integer => write!(f, "{}", "Int"), + Boolean => write!(f, "{}", "Bool"), QuoteTy => write!(f, "{}", "Quote"), VecType => write!(f, "{}", "Vector"), LetType => write!(f, "{}", "Let"), - NilType => write!(f, "()"), + NilType => write!(f, "Nil"), TypeLit => write!(f, "[type literal]"), - VecOf(ty) => write!(f, "({} ... {})", *ty, *ty), + VecOf(ty) => write!(f, "({} ...)", *ty), Arrow(a, b) => write!(f, "({} -> {})", a, b), List(types) => write!( f, @@ -67,7 +67,7 @@ impl fmt::Display for TypeError { /// expected: arr(VarType("?".to_string()), VarType("?".to_string())), /// found: Integer /// }.to_string(), - /// "invalid operator: '1'\nexpected: '(? -> ?)'\nfound: 'int'".to_string() + /// "invalid operator: '1'\nexpected: '(? -> ?)'\nfound: 'Int'".to_string() /// ); /// assert_eq!( /// InvalidArgList { @@ -75,7 +75,7 @@ impl fmt::Display for TypeError { /// expected: List(vec![Integer, Integer]), /// found: List(vec![Integer, Integer, Integer]), /// }.to_string(), - /// "invalid argument list: '(1 2 3)'\nexpected: '(int int)'\nfound: '(int int int)'".to_string() + /// "invalid argument list: '(1 2 3)'\nexpected: '(Int Int)'\nfound: '(Int Int Int)'".to_string() /// ); /// assert_eq!( /// UnboundGeneric(String::from("?")).to_string(), @@ -86,7 +86,7 @@ impl fmt::Display for TypeError { /// argtype: Integer, /// generictype: arr(VarType("T".to_string()), Integer) /// }.to_string(), - /// "incompatible argument type 'int' and generic operator type '(T -> int)'".to_string() + /// "incompatible argument type 'Int' and generic operator type '(T -> Int)'".to_string() /// ); /// ``` fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/type/util.rs b/src/type/util.rs index 23f8d1f..ad85b79 100644 --- a/src/type/util.rs +++ b/src/type/util.rs @@ -24,7 +24,7 @@ impl SExp { let argnames = ls.get(1) .ok_or(InvalidFunDef(self.clone(), NoArgumentList))? .clone().parts(); - let argtypes = ls.get(2) + let argtype = ls.get(2) .ok_or(InvalidFunDef(self.clone(), NoTypeList))? .clone(); let rettype = ls.get(3) @@ -40,9 +40,9 @@ impl SExp { }?); } - let argtypes = match argtypes.clone().multistep() { - Ok(Atom(Ty(List(v)))) => Ok(v), - Ok(Atom(Ty(t))) => Ok(vec![t]), + let argtypes = match argtype { + Atom(Ty(List(v))) => Ok(v), + Atom(Ty(t)) => Ok(vec![t]), _ => { Err(InvalidFunDef(self.clone(), InvalidArgumentList)) }, |