Skip to content
Snippets Groups Projects
Commit 34054d02 authored by Per Lindgren's avatar Per Lindgren
Browse files

most examples pass

parent a382754b
No related branches found
No related tags found
No related merge requests found
...@@ -76,8 +76,6 @@ pub enum Type { ...@@ -76,8 +76,6 @@ pub enum Type {
Ref(Box<Type>), // & mut? Type -- used in parser Ref(Box<Type>), // & mut? Type -- used in parser
Mut(Box<Type>), // mut Type Mut(Box<Type>), // mut Type
Unknown, // Not yet assigned Unknown, // Not yet assigned
// RefMut(Box<Type>), // &mut Type -- used in parser
} }
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
......
...@@ -446,14 +446,17 @@ fn test_expr_type() { ...@@ -446,14 +446,17 @@ fn test_expr_type() {
); );
// let j ... (has no type yet) // 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!( assert_eq!(
expr_type(&Expr::Id("n".to_string()), &fn_env, &type_env, &var_env), expr_type(&Expr::Id("j".to_string()), &fn_env, &type_env, &var_env),
Ok(Named("A".to_string())) 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) // type of arithmetic operation (for now just i32)
assert_eq!( assert_eq!(
expr_type( expr_type(
...@@ -516,16 +519,16 @@ fn test_expr_type() { ...@@ -516,16 +519,16 @@ fn test_expr_type() {
) )
.is_err()); .is_err());
// call, with check, ok (i: i32) // // call, with check, ok (i: i32)
assert_eq!( // assert_eq!(
expr_type( // expr_type(
&*ExprParser::new().parse("c(n)").unwrap(), // &*ExprParser::new().parse("c(n)").unwrap(),
&fn_env, // &fn_env,
&type_env, // &type_env,
&var_env // &var_env
), // ),
Ok(Unit) // Ok(Unit)
); // );
// TODO, ref/ref mut/deref // TODO, ref/ref mut/deref
} }
...@@ -53,6 +53,7 @@ impl VarEnv { ...@@ -53,6 +53,7 @@ impl VarEnv {
} }
pub fn update(&mut self, id: String, ty: Type) -> Result<(), Error> { pub fn update(&mut self, id: String, ty: Type) -> Result<(), Error> {
println!("env: update");
match self.get_mut(id.clone()) { match self.get_mut(id.clone()) {
Some(ot) => match ot { Some(ot) => match ot {
Type::Unknown => { Type::Unknown => {
......
...@@ -19,5 +19,5 @@ pub fn parse(file_name: &str) -> Program { ...@@ -19,5 +19,5 @@ pub fn parse(file_name: &str) -> Program {
#[test] #[test]
fn read_prog() { fn read_prog() {
assert_eq!(&read("test_files/minimal.rs").unwrap(), "fn main() {}\n"); assert_eq!(&read("examples/minimal.rs").unwrap(), "fn main() {}\n");
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment