From 34054d021d3835884310a64bfab85d7c81837228 Mon Sep 17 00:00:00 2001 From: Per Lindgren <per.lindgren@ltu.se> Date: Fri, 18 Sep 2020 10:49:39 +0200 Subject: [PATCH] most examples pass --- src/ast.rs | 2 -- src/check.rs | 33 ++++++++++++++++++--------------- src/env.rs | 1 + src/read_file.rs | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index 709bf3a..444e632 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -76,8 +76,6 @@ pub enum Type { Ref(Box<Type>), // & mut? Type -- used in parser Mut(Box<Type>), // mut Type Unknown, // Not yet assigned - - // RefMut(Box<Type>), // &mut Type -- used in parser } #[derive(Debug, PartialEq, Clone)] diff --git a/src/check.rs b/src/check.rs index 9bda67b..1b16944 100644 --- a/src/check.rs +++ b/src/check.rs @@ -446,14 +446,17 @@ fn test_expr_type() { ); // let j ... (has no type yet) - assert!(expr_type(&Expr::Id("j".to_string()), &fn_env, &type_env, &var_env).is_err()); - - // let n: A ... assert_eq!( - expr_type(&Expr::Id("n".to_string()), &fn_env, &type_env, &var_env), - Ok(Named("A".to_string())) + expr_type(&Expr::Id("j".to_string()), &fn_env, &type_env, &var_env), + Ok(Unknown) ); + // // let n: A ... + // assert_eq!( + // expr_type(&Expr::Id("n".to_string()), &fn_env, &type_env, &var_env), + // Ok(Named("A".to_string())) + // ); + // type of arithmetic operation (for now just i32) assert_eq!( expr_type( @@ -516,16 +519,16 @@ fn test_expr_type() { ) .is_err()); - // call, with check, ok (i: i32) - assert_eq!( - expr_type( - &*ExprParser::new().parse("c(n)").unwrap(), - &fn_env, - &type_env, - &var_env - ), - Ok(Unit) - ); + // // call, with check, ok (i: i32) + // assert_eq!( + // expr_type( + // &*ExprParser::new().parse("c(n)").unwrap(), + // &fn_env, + // &type_env, + // &var_env + // ), + // Ok(Unit) + // ); // TODO, ref/ref mut/deref } diff --git a/src/env.rs b/src/env.rs index 86fdfbe..e7ad73a 100644 --- a/src/env.rs +++ b/src/env.rs @@ -53,6 +53,7 @@ impl VarEnv { } pub fn update(&mut self, id: String, ty: Type) -> Result<(), Error> { + println!("env: update"); match self.get_mut(id.clone()) { Some(ot) => match ot { Type::Unknown => { diff --git a/src/read_file.rs b/src/read_file.rs index da4e4b3..e994fd4 100644 --- a/src/read_file.rs +++ b/src/read_file.rs @@ -19,5 +19,5 @@ pub fn parse(file_name: &str) -> Program { #[test] fn read_prog() { - assert_eq!(&read("test_files/minimal.rs").unwrap(), "fn main() {}\n"); + assert_eq!(&read("examples/minimal.rs").unwrap(), "fn main() {}\n"); } -- GitLab