diff --git a/reid_src/std.reid b/reid/src/lib/std.reid similarity index 100% rename from reid_src/std.reid rename to reid/src/lib/std.reid diff --git a/reid/src/mir/linker.rs b/reid/src/mir/linker.rs index a955c46..7a1355b 100644 --- a/reid/src/mir/linker.rs +++ b/reid/src/mir/linker.rs @@ -15,6 +15,8 @@ use super::{ Context, FunctionDefinition, Import, Metadata, Module, }; +pub static STD_SOURCE: &str = include_str!("../lib/std.reid"); + #[derive(thiserror::Error, Debug, Clone)] pub enum ErrorKind { #[error("Unable to import inner modules, not yet supported: {0}")] @@ -39,6 +41,19 @@ pub enum ErrorKind { FunctionIsPrivate(String, String), } +fn compile_main() -> 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 mut refs = super::typerefs::TypeRefs::default(); + mir_context.pass(&mut super::typeinference::TypeInference { refs: &mut refs }); + mir_context.pass(&mut super::typecheck::TypeCheck { refs: &mut refs }); + + let std_compiled = mir_context.modules.remove(0); + std_compiled +} + /// Struct used to implement a type-checking pass that can be performed on the /// MIR. pub struct LinkerPass; @@ -71,6 +86,8 @@ impl Pass for LinkerPass { modules.insert(module.name.clone(), Rc::new(RefCell::new(module))); } + modules.insert("std".to_owned(), Rc::new(RefCell::new(compile_main()))); + let mut modules_to_process: Vec>> = modules.values().cloned().collect(); while let Some(module) = modules_to_process.pop() {