Start building out type inference.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::backend::Backend;
|
||||
use crate::syntax::Program as Syntax;
|
||||
use crate::{backend::Backend, ir::TypeInferenceResult};
|
||||
use codespan_reporting::{
|
||||
diagnostic::Diagnostic,
|
||||
files::SimpleFiles,
|
||||
@@ -99,8 +99,38 @@ impl Compiler {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
// Now that we've validated it, turn it into IR.
|
||||
let ir = syntax.type_infer();
|
||||
// Now that we've validated it, let's do type inference, potentially turning
|
||||
// into IR while we're at it.
|
||||
let ir = match syntax.type_infer() {
|
||||
TypeInferenceResult::Failure {
|
||||
mut errors,
|
||||
mut warnings,
|
||||
} => {
|
||||
let messages = errors
|
||||
.drain(..)
|
||||
.map(Into::into)
|
||||
.chain(warnings.drain(..).map(Into::into));
|
||||
|
||||
for message in messages {
|
||||
self.emit(message);
|
||||
}
|
||||
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
TypeInferenceResult::Success {
|
||||
result,
|
||||
mut warnings,
|
||||
} => {
|
||||
let messages = warnings.drain(..).map(Into::into);
|
||||
|
||||
for message in messages {
|
||||
self.emit(message);
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
};
|
||||
|
||||
// Finally, send all this to Cranelift for conversion into an object file.
|
||||
let mut backend = Backend::object_file(Triple::host())?;
|
||||
|
||||
Reference in New Issue
Block a user