diff --git a/crates/erg_compiler/artifact.rs b/crates/erg_compiler/artifact.rs index 3a5de641..02b12f77 100644 --- a/crates/erg_compiler/artifact.rs +++ b/crates/erg_compiler/artifact.rs @@ -103,4 +103,9 @@ pub trait Buildable { fn get_context(&self) -> Option<&ModuleContext>; } -pub trait BuildRunnable: Buildable + Runnable + 'static {} +pub trait BuildRunnable: Buildable + Runnable + 'static { + fn build_module(&mut self) -> Result, IncompleteArtifact> { + let src = self.cfg_mut().input.read(); + self.build(src, "exec") + } +} diff --git a/crates/erg_compiler/build_hir.rs b/crates/erg_compiler/build_hir.rs index d6f9a7fe..fb08df63 100644 --- a/crates/erg_compiler/build_hir.rs +++ b/crates/erg_compiler/build_hir.rs @@ -179,6 +179,11 @@ impl HIRBuilder { self.check(artifact.ast, mode) } + pub fn build_module(&mut self) -> Result { + let src = self.cfg_mut().input.read(); + self.build(src, "exec") + } + pub fn pop_mod_ctx(&mut self) -> Option { self.lowerer.pop_mod_ctx() } diff --git a/crates/erg_compiler/compile.rs b/crates/erg_compiler/compile.rs index b1c6d33c..c1b96c2b 100644 --- a/crates/erg_compiler/compile.rs +++ b/crates/erg_compiler/compile.rs @@ -239,6 +239,11 @@ impl Compiler { Ok(CompleteArtifact::new(codeobj, arti.warns)) } + pub fn compile_module(&mut self) -> Result, ErrorArtifact> { + let src = self.cfg.input.read(); + self.compile(src, "exec") + } + pub fn eval_compile( &mut self, src: String, diff --git a/crates/erg_compiler/transpile.rs b/crates/erg_compiler/transpile.rs index 9ed22cf7..3ca92e58 100644 --- a/crates/erg_compiler/transpile.rs +++ b/crates/erg_compiler/transpile.rs @@ -223,6 +223,11 @@ impl Transpiler { Ok(CompleteArtifact::new(script, artifact.warns)) } + pub fn transpile_module(&mut self) -> Result, ErrorArtifact> { + let src = self.cfg.input.read(); + self.transpile(src, "exec") + } + fn build_link_desugar( &mut self, src: String,