Skip to content

Commit 60f82ba

Browse files
committed
feat: add BuildRunnable::build_module
1 parent 32a7780 commit 60f82ba

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

crates/erg_compiler/artifact.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,9 @@ pub trait Buildable<T = HIR> {
103103
fn get_context(&self) -> Option<&ModuleContext>;
104104
}
105105

106-
pub trait BuildRunnable<T = HIR>: Buildable<T> + Runnable + 'static {}
106+
pub trait BuildRunnable<T = HIR>: Buildable<T> + Runnable + 'static {
107+
fn build_module(&mut self) -> Result<CompleteArtifact<T>, IncompleteArtifact<T>> {
108+
let src = self.cfg_mut().input.read();
109+
self.build(src, "exec")
110+
}
111+
}

crates/erg_compiler/build_hir.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ impl HIRBuilder {
179179
self.check(artifact.ast, mode)
180180
}
181181

182+
pub fn build_module(&mut self) -> Result<CompleteArtifact, IncompleteArtifact> {
183+
let src = self.cfg_mut().input.read();
184+
self.build(src, "exec")
185+
}
186+
182187
pub fn pop_mod_ctx(&mut self) -> Option<ModuleContext> {
183188
self.lowerer.pop_mod_ctx()
184189
}

crates/erg_compiler/compile.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ impl Compiler {
239239
Ok(CompleteArtifact::new(codeobj, arti.warns))
240240
}
241241

242+
pub fn compile_module(&mut self) -> Result<CompleteArtifact<CodeObj>, ErrorArtifact> {
243+
let src = self.cfg.input.read();
244+
self.compile(src, "exec")
245+
}
246+
242247
pub fn eval_compile(
243248
&mut self,
244249
src: String,

crates/erg_compiler/transpile.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ impl Transpiler {
223223
Ok(CompleteArtifact::new(script, artifact.warns))
224224
}
225225

226+
pub fn transpile_module(&mut self) -> Result<CompleteArtifact<PyScript>, ErrorArtifact> {
227+
let src = self.cfg.input.read();
228+
self.transpile(src, "exec")
229+
}
230+
226231
fn build_link_desugar(
227232
&mut self,
228233
src: String,

0 commit comments

Comments
 (0)