From 8062ed87d30fa7628f26cfd7bb94bb0e7401752b Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sat, 9 Aug 2025 21:18:48 +0300 Subject: Revert adding of print (its behavior was poorly designed). This reverts commit 3e1bf7f9946efe70d452c71494ac77ed39110804. --- src/parse/parsetree.rs | 1 - src/sexp/display.rs | 1 - src/sexp/mod.rs | 4 +--- src/sexp/step.rs | 15 --------------- src/sexp/util.rs | 7 ------- src/type/check.rs | 24 +++++++++++++----------- src/type/display.rs | 8 ++++---- src/type/mod.rs | 2 +- 8 files changed, 19 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/parse/parsetree.rs b/src/parse/parsetree.rs index 8e2b856..75758dc 100644 --- a/src/parse/parsetree.rs +++ b/src/parse/parsetree.rs @@ -113,7 +113,6 @@ fn tokens_to_ast_inner( Some(Sym(s)) if s == "false" => Ok(Atom(False)), Some(Sym(s)) if s == "quote" => Ok(Atom(Quote)), Some(Sym(s)) if s == "vector" => Ok(Atom(Vector)), - Some(Sym(s)) if s == "print" => Ok(Atom(Print)), Some(Sym(s)) if s == "let" => Ok(Atom(Let)), Some(Sym(s)) => Ok(Atom(Var(s))), Some(ParClose) => break, diff --git a/src/sexp/display.rs b/src/sexp/display.rs index dc5d6cb..c3db144 100644 --- a/src/sexp/display.rs +++ b/src/sexp/display.rs @@ -27,7 +27,6 @@ impl fmt::Display for SLeaf { Var(s) => s.to_string(), Quote => "quote".to_string(), Vector => "vector".to_string(), - Print => "print".to_string(), Let => "let".to_string(), Nil => "()".to_string(), }) diff --git a/src/sexp/mod.rs b/src/sexp/mod.rs index c674ee9..7aa517b 100644 --- a/src/sexp/mod.rs +++ b/src/sexp/mod.rs @@ -33,8 +33,6 @@ pub enum SLeaf { Let, - Print, - Int(i32), True, False, @@ -71,7 +69,7 @@ impl SExp { SCons(a, b) => SCons(a.clone(), b.clone()).check_let().is_some() || ( - (**a == Atom(Quote) || **a == Atom(Vector) || **a == Atom(Print)) + (**a == Atom(Quote) || **a == Atom(Vector)) && b.consists_of_values() ), Atom(Var(_)) => false, diff --git a/src/sexp/step.rs b/src/sexp/step.rs index 94f6381..816582c 100644 --- a/src/sexp/step.rs +++ b/src/sexp/step.rs @@ -309,21 +309,6 @@ impl SExp { None => panic!("unreachable as per match guard arm"), }, - // prints - SCons(op, l) if op.clone().is_print() => match *op { - SCons(_, b) => { - println!("{}", match *b { - SCons(a, b) if *b == Atom(Nil) => *a, - t => t, - }); - Ok(match *l { - SCons(a, b) if *b == Atom(Nil) => *a, - t => t - }) - }, - Atom(_) => panic!("unreachable as per match arm guard"), - }, - // op value and a1 .. an values, and b0, b1 .. bn not values // --------------------------------------------------------- diff --git a/src/sexp/util.rs b/src/sexp/util.rs index 507455f..a28aaad 100644 --- a/src/sexp/util.rs +++ b/src/sexp/util.rs @@ -86,11 +86,4 @@ impl SExp { _ => None } } - - pub fn is_print(&self) -> bool { - match self { - SCons(op, _) if **op == Atom(Print) => true, - _ => false - } - } } diff --git a/src/type/check.rs b/src/type/check.rs index 91ca422..e536ce7 100644 --- a/src/type/check.rs +++ b/src/type/check.rs @@ -163,11 +163,7 @@ impl SExp { /// }; /// ``` pub fn type_check(&self) -> Result { - let ty = self.infer_type(HashMap::new())?; - match ty.is_concrete() { - Ok(()) => Ok(ty), - Err(s) => Err(UnboundGeneric(ty, s)), - } + self.infer_type(HashMap::new()) } @@ -198,7 +194,6 @@ impl SExp { List(vec![VecType, vecof(vt("T"))]) )), Atom(Let) => Ok(LetType), - Atom(Print) => Ok(arr(vt("_"), arr(vt("T"), vt("T")))), SCons(op, l) => { @@ -303,11 +298,10 @@ impl Type { restype = restype.subst(&name, &ty); } - //match restype.is_concrete() { - // Ok(()) => Ok(arr(argtype.clone(), restype)), - // Err(unbound) => Err(UnboundGeneric(unbound)), - //} - Ok(arr(argtype.clone(), restype)) + match restype.is_concrete() { + Ok(()) => Ok(arr(argtype.clone(), restype)), + Err(unbound) => Err(UnboundGeneric(unbound)), + } }, _ => Err(OtherError) } @@ -384,6 +378,14 @@ impl Type { mod tests { use super::{*, TypeError}; + #[test] + fn test_failing_infer_generics() { + assert_eq!( + arr(Integer, VarType("X".to_string())).infer_generics(&Integer), + Err(TypeError::UnboundGeneric(String::from("X"))) + ); + } + #[test] fn test_infer_generics() { diff --git a/src/type/display.rs b/src/type/display.rs index f859dc3..4a9b54a 100644 --- a/src/type/display.rs +++ b/src/type/display.rs @@ -67,8 +67,8 @@ impl fmt::Display for TypeError { /// "invalid argument list: '(1 2 3)'\nexpected: '(Int Int)'\nfound: '(Int Int Int)'".to_string() /// ); /// assert_eq!( - /// UnboundGeneric(arr(Integer, vt("?")), String::from("?")).to_string(), - /// "unbound generic type in '(Int -> ?)': '?'".to_string() + /// UnboundGeneric(String::from("?")).to_string(), + /// "unbound generic type: '?'".to_string() /// ); /// assert_eq!( /// ArgumentsDontMatchGeneric { @@ -80,8 +80,8 @@ impl fmt::Display for TypeError { /// ``` fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - UndefinedVariable(name) => write!(f, "undefined variable: '{}'", name), - UnboundGeneric(ty, name) => write!(f, "unbound generic type in '{}': '{}'", ty, name), + UndefinedVariable(name) => write!(f, "undefined variable: '{}'", name), + UnboundGeneric(name) => write!(f, "unbound generic type: '{}'", name), InvalidOperator { operator, expected, found } => { write!( f, diff --git a/src/type/mod.rs b/src/type/mod.rs index 6f5c6dc..afb5a0b 100644 --- a/src/type/mod.rs +++ b/src/type/mod.rs @@ -40,7 +40,7 @@ pub enum TypeError { UndefinedVariable(String), - UnboundGeneric(Type, String), + UnboundGeneric(String), InvalidOperator { operator: SExp, -- cgit v1.2.3