Compare commits
No commits in common. "5acd1624fd2fd309eed0a6364efc937844b68746" and "fa4df50a04b652c0054b0e94c055ec3fa421fcc3" have entirely different histories.
5acd1624fd
...
fa4df50a04
@ -100,46 +100,6 @@ pub fn compile_module(
|
|||||||
Ok(ast_module.process())
|
Ok(ast_module.process())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn perform_all_passes(context: &mut mir::Context) -> Result<(), ReidError> {
|
|
||||||
let state = context.pass(&mut LinkerPass);
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
dbg!(&context);
|
|
||||||
println!("{}", &context);
|
|
||||||
}
|
|
||||||
|
|
||||||
if !state.errors.is_empty() {
|
|
||||||
return Err(ReidError::LinkerErrors(state.errors));
|
|
||||||
}
|
|
||||||
|
|
||||||
let refs = TypeRefs::default();
|
|
||||||
|
|
||||||
let state = context.pass(&mut TypeInference { refs: &refs });
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
dbg!(&state, &refs);
|
|
||||||
dbg!(&context);
|
|
||||||
println!("{}", &context);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if !state.errors.is_empty() {
|
|
||||||
// return Err(ReidError::TypeInferenceErrors(state.errors));
|
|
||||||
// }
|
|
||||||
|
|
||||||
let state = context.pass(&mut TypeCheck { refs: &refs });
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
dbg!(&state);
|
|
||||||
println!("{}", &context);
|
|
||||||
}
|
|
||||||
|
|
||||||
if !state.errors.is_empty() {
|
|
||||||
return Err(ReidError::TypeCheckErrors(state.errors));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Takes in a bit of source code, parses and compiles it and produces `hello.o`
|
/// Takes in a bit of source code, parses and compiles it and produces `hello.o`
|
||||||
/// and `hello.asm` from it, which can be linked using `ld` to produce an
|
/// and `hello.asm` from it, which can be linked using `ld` to produce an
|
||||||
/// executable file.
|
/// executable file.
|
||||||
@ -158,7 +118,32 @@ pub fn compile(source: &str, path: PathBuf) -> Result<String, ReidError> {
|
|||||||
|
|
||||||
println!("{}", &mir_context);
|
println!("{}", &mir_context);
|
||||||
|
|
||||||
perform_all_passes(&mut mir_context);
|
let state = mir_context.pass(&mut LinkerPass);
|
||||||
|
dbg!(&state);
|
||||||
|
println!("{}", &mir_context);
|
||||||
|
|
||||||
|
if !state.errors.is_empty() {
|
||||||
|
return Err(ReidError::LinkerErrors(state.errors));
|
||||||
|
}
|
||||||
|
|
||||||
|
let refs = TypeRefs::default();
|
||||||
|
|
||||||
|
let state = mir_context.pass(&mut TypeInference { refs: &refs });
|
||||||
|
dbg!(&state, &refs);
|
||||||
|
dbg!(&mir_context);
|
||||||
|
println!("{}", &mir_context);
|
||||||
|
|
||||||
|
// if !state.errors.is_empty() {
|
||||||
|
// return Err(ReidError::TypeInferenceErrors(state.errors));
|
||||||
|
// }
|
||||||
|
|
||||||
|
let state = mir_context.pass(&mut TypeCheck { refs: &refs });
|
||||||
|
dbg!(&state);
|
||||||
|
println!("{}", &mir_context);
|
||||||
|
|
||||||
|
if !state.errors.is_empty() {
|
||||||
|
return Err(ReidError::TypeCheckErrors(state.errors));
|
||||||
|
}
|
||||||
|
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
let codegen_modules = mir_context.codegen(&mut context);
|
let codegen_modules = mir_context.codegen(&mut context);
|
||||||
|
@ -15,8 +15,6 @@ use super::{
|
|||||||
Context, FunctionDefinition, Import, Metadata, Module,
|
Context, FunctionDefinition, Import, Metadata, Module,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub static STD_SOURCE: &str = include_str!("../../lib/std.reid");
|
|
||||||
|
|
||||||
#[derive(thiserror::Error, Debug, Clone)]
|
#[derive(thiserror::Error, Debug, Clone)]
|
||||||
pub enum ErrorKind {
|
pub enum ErrorKind {
|
||||||
#[error("Unable to import inner modules, not yet supported: {0}")]
|
#[error("Unable to import inner modules, not yet supported: {0}")]
|
||||||
@ -41,15 +39,6 @@ pub enum ErrorKind {
|
|||||||
FunctionIsPrivate(String, String),
|
FunctionIsPrivate(String, String),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compile_std() -> super::Module {
|
|
||||||
let module = compile_module(STD_SOURCE, "standard_library".to_owned(), None, false).unwrap();
|
|
||||||
|
|
||||||
let mut mir_context = super::Context::from(vec![module], Default::default());
|
|
||||||
|
|
||||||
let std_compiled = mir_context.modules.remove(0);
|
|
||||||
std_compiled
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Struct used to implement a type-checking pass that can be performed on the
|
/// Struct used to implement a type-checking pass that can be performed on the
|
||||||
/// MIR.
|
/// MIR.
|
||||||
pub struct LinkerPass;
|
pub struct LinkerPass;
|
||||||
@ -82,8 +71,6 @@ impl Pass for LinkerPass {
|
|||||||
modules.insert(module.name.clone(), Rc::new(RefCell::new(module)));
|
modules.insert(module.name.clone(), Rc::new(RefCell::new(module)));
|
||||||
}
|
}
|
||||||
|
|
||||||
modules.insert("std".to_owned(), Rc::new(RefCell::new(compile_std())));
|
|
||||||
|
|
||||||
let mut modules_to_process: Vec<Rc<RefCell<Module>>> = modules.values().cloned().collect();
|
let mut modules_to_process: Vec<Rc<RefCell<Module>>> = modules.values().cloned().collect();
|
||||||
|
|
||||||
while let Some(module) = modules_to_process.pop() {
|
while let Some(module) = modules_to_process.pop() {
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
use reid::{
|
|
||||||
mir::{self, linker::compile_std},
|
|
||||||
perform_all_passes,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn compiles() {
|
|
||||||
let _ = compile_std();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn passes_all_passes() {
|
|
||||||
let mut std = compile_std();
|
|
||||||
|
|
||||||
// Needed to pass linker-pass
|
|
||||||
std.is_main = true;
|
|
||||||
|
|
||||||
assert_err(perform_all_passes(&mut mir::Context {
|
|
||||||
modules: vec![std],
|
|
||||||
base: Default::default(),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn assert_err<T, U: std::fmt::Debug>(value: Result<T, U>) {
|
|
||||||
match value {
|
|
||||||
Ok(_) => {}
|
|
||||||
Err(err) => assert!(false, "{:?}", err),
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user