Type checking beginnings
This commit is contained in:
parent
8d2a65b44e
commit
f825c87397
@ -77,6 +77,7 @@ impl TraceArtifact {
|
|||||||
let color = match stage {
|
let color = match stage {
|
||||||
"parse_trace" => "red",
|
"parse_trace" => "red",
|
||||||
"tokens" => "green",
|
"tokens" => "green",
|
||||||
|
"type_check" => "magenta",
|
||||||
_ => "blue",
|
_ => "blue",
|
||||||
};
|
};
|
||||||
TraceArtifact { stage_name: stage.to_string(), debug_output: debug, text_color: color}
|
TraceArtifact { stage_name: stage.to_string(), debug_output: debug, text_color: color}
|
||||||
|
@ -3,6 +3,11 @@ use schala_lang::parsing::AST;
|
|||||||
pub struct ReplState {
|
pub struct ReplState {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum TypeCheck {
|
||||||
|
OK,
|
||||||
|
Error(String)
|
||||||
|
}
|
||||||
|
|
||||||
impl ReplState {
|
impl ReplState {
|
||||||
pub fn new() -> ReplState {
|
pub fn new() -> ReplState {
|
||||||
ReplState { }
|
ReplState { }
|
||||||
@ -11,5 +16,9 @@ impl ReplState {
|
|||||||
pub fn evaluate(&mut self, ast: AST) -> String {
|
pub fn evaluate(&mut self, ast: AST) -> String {
|
||||||
format!("Evaluated AST: {:?}", ast)
|
format!("Evaluated AST: {:?}", ast)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn type_check(&mut self, ast: &AST) -> TypeCheck {
|
||||||
|
TypeCheck::Error("type lol".to_string())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ use language::{ProgrammingLanguageInterface, EvalOptions, TraceArtifact, ReplOut
|
|||||||
mod parsing;
|
mod parsing;
|
||||||
mod eval;
|
mod eval;
|
||||||
|
|
||||||
|
use self::eval::TypeCheck;
|
||||||
|
|
||||||
pub struct Schala {
|
pub struct Schala {
|
||||||
state: eval::ReplState
|
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);
|
let evaluation_output = self.state.evaluate(ast);
|
||||||
output.add_output(evaluation_output);
|
output.add_output(evaluation_output);
|
||||||
return output;
|
return output;
|
||||||
|
Loading…
Reference in New Issue
Block a user