From 3f90b46dc890c48bc17a8c54c89dd2a907e6f5d4 Mon Sep 17 00:00:00 2001 From: sofia Date: Mon, 14 Jul 2025 22:33:04 +0300 Subject: [PATCH] Include stdlib in executable --- {reid_src => reid/src/lib}/std.reid | 0 reid/src/mir/linker.rs | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) rename {reid_src => reid/src/lib}/std.reid (100%) 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() {