diff --git a/compiler/erg_common/traits.rs b/compiler/erg_common/traits.rs index 3109b555..c92ad3bf 100644 --- a/compiler/erg_common/traits.rs +++ b/compiler/erg_common/traits.rs @@ -386,6 +386,7 @@ pub trait Runnable: Sized + Default { const NAME: &'static str; fn new(cfg: ErgConfig) -> Self; fn cfg(&self) -> &ErgConfig; + fn cfg_mut(&mut self) -> &mut ErgConfig; fn finish(&mut self); // called when the :exit command is received. /// Erase all but immutable information. fn initialize(&mut self); @@ -397,6 +398,9 @@ pub trait Runnable: Sized + Default { fn input(&self) -> &Input { &self.cfg().input } + fn set_input(&mut self, input: Input) { + self.cfg_mut().input = input; + } fn start_message(&self) -> String { format!( "{} {SEMVER} (tags/?:{GIT_HASH_SHORT}, {BUILD_DATE}) on {ARCH}/{OS}\n", diff --git a/compiler/erg_compiler/build_hir.rs b/compiler/erg_compiler/build_hir.rs index 9321eeb5..74a7b7c2 100644 --- a/compiler/erg_compiler/build_hir.rs +++ b/compiler/erg_compiler/build_hir.rs @@ -40,6 +40,10 @@ impl Runnable for HIRBuilder { fn cfg(&self) -> &ErgConfig { self.lowerer.cfg() } + #[inline] + fn cfg_mut(&mut self) -> &mut ErgConfig { + self.lowerer.cfg_mut() + } #[inline] fn finish(&mut self) {} diff --git a/compiler/erg_compiler/compile.rs b/compiler/erg_compiler/compile.rs index c4f68338..daf89106 100644 --- a/compiler/erg_compiler/compile.rs +++ b/compiler/erg_compiler/compile.rs @@ -127,6 +127,10 @@ impl Runnable for Compiler { fn cfg(&self) -> &ErgConfig { &self.cfg } + #[inline] + fn cfg_mut(&mut self) -> &mut ErgConfig { + &mut self.cfg + } #[inline] fn finish(&mut self) {} diff --git a/compiler/erg_compiler/lower.rs b/compiler/erg_compiler/lower.rs index e528afeb..4a4ad181 100644 --- a/compiler/erg_compiler/lower.rs +++ b/compiler/erg_compiler/lower.rs @@ -71,6 +71,10 @@ impl Runnable for ASTLowerer { fn cfg(&self) -> &ErgConfig { &self.cfg } + #[inline] + fn cfg_mut(&mut self) -> &mut ErgConfig { + &mut self.cfg + } fn new(cfg: ErgConfig) -> Self { Self::new_with_cache( diff --git a/compiler/erg_compiler/transpile.rs b/compiler/erg_compiler/transpile.rs index eaed716f..2e7494d6 100644 --- a/compiler/erg_compiler/transpile.rs +++ b/compiler/erg_compiler/transpile.rs @@ -124,6 +124,10 @@ impl Runnable for Transpiler { fn cfg(&self) -> &ErgConfig { &self.cfg } + #[inline] + fn cfg_mut(&mut self) -> &mut ErgConfig { + &mut self.cfg + } #[inline] fn finish(&mut self) {} diff --git a/compiler/erg_parser/build_ast.rs b/compiler/erg_parser/build_ast.rs index 5dcb6a98..c4fdf587 100644 --- a/compiler/erg_parser/build_ast.rs +++ b/compiler/erg_parser/build_ast.rs @@ -29,6 +29,10 @@ impl Runnable for ASTBuilder { fn cfg(&self) -> &ErgConfig { self.runner.cfg() } + #[inline] + fn cfg_mut(&mut self) -> &mut ErgConfig { + self.runner.cfg_mut() + } #[inline] fn finish(&mut self) {} diff --git a/compiler/erg_parser/lex.rs b/compiler/erg_parser/lex.rs index d617a35a..bbde23bf 100644 --- a/compiler/erg_parser/lex.rs +++ b/compiler/erg_parser/lex.rs @@ -33,6 +33,10 @@ impl Runnable for LexerRunner { fn cfg(&self) -> &ErgConfig { &self.cfg } + #[inline] + fn cfg_mut(&mut self) -> &mut ErgConfig { + &mut self.cfg + } #[inline] fn finish(&mut self) {} diff --git a/compiler/erg_parser/parse.rs b/compiler/erg_parser/parse.rs index ca8bb6ed..70c0ef13 100644 --- a/compiler/erg_parser/parse.rs +++ b/compiler/erg_parser/parse.rs @@ -183,6 +183,10 @@ impl Runnable for ParserRunner { fn cfg(&self) -> &ErgConfig { &self.cfg } + #[inline] + fn cfg_mut(&mut self) -> &mut ErgConfig { + &mut self.cfg + } #[inline] fn finish(&mut self) {} diff --git a/src/dummy.rs b/src/dummy.rs index 94d30d43..0f0d1d4a 100644 --- a/src/dummy.rs +++ b/src/dummy.rs @@ -48,6 +48,10 @@ impl Runnable for DummyVM { fn cfg(&self) -> &ErgConfig { &self.compiler.cfg } + #[inline] + fn cfg_mut(&mut self) -> &mut ErgConfig { + &mut self.compiler.cfg + } fn new(cfg: ErgConfig) -> Self { let stream = if cfg.input.is_repl() {