Start building out type inference.

This commit is contained in:
2023-06-21 21:56:54 -07:00
parent 3687785540
commit 1ad3d6c517
14 changed files with 1286 additions and 305 deletions

View File

@@ -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())?;