From f825c87397ca0cd39ecb5e87a07074ce1ce2c16c Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 1 Oct 2017 00:48:08 -0700 Subject: [PATCH] Type checking beginnings --- src/language.rs | 1 + src/schala_lang/eval.rs | 9 +++++++++ src/schala_lang/mod.rs | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/language.rs b/src/language.rs index 4aaa8b5..fcc0bb1 100644 --- a/src/language.rs +++ b/src/language.rs @@ -77,6 +77,7 @@ impl TraceArtifact { let color = match stage { "parse_trace" => "red", "tokens" => "green", + "type_check" => "magenta", _ => "blue", }; TraceArtifact { stage_name: stage.to_string(), debug_output: debug, text_color: color} diff --git a/src/schala_lang/eval.rs b/src/schala_lang/eval.rs index 08d203b..10a27f1 100644 --- a/src/schala_lang/eval.rs +++ b/src/schala_lang/eval.rs @@ -3,6 +3,11 @@ use schala_lang::parsing::AST; pub struct ReplState { } +pub enum TypeCheck { + OK, + Error(String) +} + impl ReplState { pub fn new() -> ReplState { ReplState { } @@ -11,5 +16,9 @@ impl ReplState { pub fn evaluate(&mut self, ast: AST) -> String { format!("Evaluated AST: {:?}", ast) } + + pub fn type_check(&mut self, ast: &AST) -> TypeCheck { + TypeCheck::Error("type lol".to_string()) + } } diff --git a/src/schala_lang/mod.rs b/src/schala_lang/mod.rs index 0c28338..a8c69ea 100644 --- a/src/schala_lang/mod.rs +++ b/src/schala_lang/mod.rs @@ -4,6 +4,8 @@ use language::{ProgrammingLanguageInterface, EvalOptions, TraceArtifact, ReplOut mod parsing; mod eval; +use self::eval::TypeCheck; + pub struct Schala { state: eval::ReplState } @@ -53,6 +55,15 @@ impl ProgrammingLanguageInterface for Schala { } }; + match self.state.type_check(&ast) { + TypeCheck::OK => (), + TypeCheck::Error(s) => { + output.add_artifact(TraceArtifact::new("type_check", s)); + output.add_output(format!("Type error")); + return output; + } + } + let evaluation_output = self.state.evaluate(ast); output.add_output(evaluation_output); return output;