From e412fb9a89565ab4af38ab2e31125bbdf34142a5 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 7 Oct 2017 22:08:48 -0700 Subject: [PATCH] Convert type-checking function type --- src/schala_lang/mod.rs | 8 ++++---- src/schala_lang/type_check.rs | 17 ++++++----------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/schala_lang/mod.rs b/src/schala_lang/mod.rs index c0758e1..87c194b 100644 --- a/src/schala_lang/mod.rs +++ b/src/schala_lang/mod.rs @@ -5,7 +5,7 @@ mod parsing; mod type_check; mod eval; -use self::type_check::{TypeContext, TypeCheckResult}; +use self::type_check::{TypeContext}; pub struct Schala { state: eval::ReplState, @@ -63,9 +63,9 @@ impl ProgrammingLanguageInterface for Schala { }; match self.type_context.type_check(&ast) { - TypeCheckResult::OK => (), - TypeCheckResult::Error(s) => { - output.add_artifact(TraceArtifact::new("type_check", s)); + Ok(t) => (), + Err(msg) => { + output.add_artifact(TraceArtifact::new("type_check", msg)); output.add_output(format!("Type error")); return output; } diff --git a/src/schala_lang/type_check.rs b/src/schala_lang/type_check.rs index ad31da4..379d379 100644 --- a/src/schala_lang/type_check.rs +++ b/src/schala_lang/type_check.rs @@ -22,16 +22,11 @@ impl TypeContext { } } -pub enum TypeCheckResult { - OK, - Error(String) -} -impl TypeCheckResult { - fn new(msg: &str) -> TypeCheckResult { - TypeCheckResult::Error(msg.to_string()) - } +pub struct SchalaType { } +type TypeCheckResult = Result; + // from Niko's talk /* fn type_check(expression, expected_ty) -> Ty { let ty = bare_type_check(expression, expected_type); @@ -53,14 +48,14 @@ impl TypeContext { for statement in ast.0.iter() { match statement { &Statement::Declaration(ref _decl) => { - return TypeCheckResult::new("Declarations not supported"); + return Err(format!("Declarations not supported")); }, &Statement::ExpressionStatement(ref expr) => { match (&expr.0, &expr.1) { (&IntLiteral(_), &Some(ref t)) => { match t { &TypeAnno::Singleton { ref name, ref params } if **name == "Int" && params.len() == 0 => (), - t => return TypeCheckResult::new(&format!("Bad type {:?} for int literal", t)), + t => return Err(format!("Bad type {:?} for int literal", t)), } }, _ => (), @@ -68,6 +63,6 @@ impl TypeContext { } } } - TypeCheckResult::OK + Ok(SchalaType { }) } }