feat: add BuildRunnable::build_module

This commit is contained in:
Shunsuke Shibayama 2023-07-03 01:55:28 +09:00
parent 32a7780581
commit 60f82ba2c1
4 changed files with 21 additions and 1 deletions

View file

@ -103,4 +103,9 @@ pub trait Buildable<T = HIR> {
fn get_context(&self) -> Option<&ModuleContext>; fn get_context(&self) -> Option<&ModuleContext>;
} }
pub trait BuildRunnable<T = HIR>: Buildable<T> + Runnable + 'static {} pub trait BuildRunnable<T = HIR>: Buildable<T> + Runnable + 'static {
fn build_module(&mut self) -> Result<CompleteArtifact<T>, IncompleteArtifact<T>> {
let src = self.cfg_mut().input.read();
self.build(src, "exec")
}
}

View file

@ -179,6 +179,11 @@ impl HIRBuilder {
self.check(artifact.ast, mode) self.check(artifact.ast, mode)
} }
pub fn build_module(&mut self) -> Result<CompleteArtifact, IncompleteArtifact> {
let src = self.cfg_mut().input.read();
self.build(src, "exec")
}
pub fn pop_mod_ctx(&mut self) -> Option<ModuleContext> { pub fn pop_mod_ctx(&mut self) -> Option<ModuleContext> {
self.lowerer.pop_mod_ctx() self.lowerer.pop_mod_ctx()
} }

View file

@ -239,6 +239,11 @@ impl Compiler {
Ok(CompleteArtifact::new(codeobj, arti.warns)) Ok(CompleteArtifact::new(codeobj, arti.warns))
} }
pub fn compile_module(&mut self) -> Result<CompleteArtifact<CodeObj>, ErrorArtifact> {
let src = self.cfg.input.read();
self.compile(src, "exec")
}
pub fn eval_compile( pub fn eval_compile(
&mut self, &mut self,
src: String, src: String,

View file

@ -223,6 +223,11 @@ impl Transpiler {
Ok(CompleteArtifact::new(script, artifact.warns)) Ok(CompleteArtifact::new(script, artifact.warns))
} }
pub fn transpile_module(&mut self) -> Result<CompleteArtifact<PyScript>, ErrorArtifact> {
let src = self.cfg.input.read();
self.transpile(src, "exec")
}
fn build_link_desugar( fn build_link_desugar(
&mut self, &mut self,
src: String, src: String,