diff --git a/compiler/erg_common/config.rs b/compiler/erg_common/config.rs index 53a25ca2..92ed3e2e 100644 --- a/compiler/erg_common/config.rs +++ b/compiler/erg_common/config.rs @@ -38,7 +38,7 @@ impl Input { pub fn enclosed_name(&self) -> &str { match self { - Self::File(filename) => filename.to_str().unwrap_or("???"), + Self::File(filename) => filename.to_str().unwrap_or("_"), Self::REPL | Self::Pipe(_) => "", Self::Str(_) => "", Self::Dummy => "", @@ -47,7 +47,7 @@ impl Input { pub fn full_path(&self) -> &str { match self { - Self::File(filename) => filename.to_str().unwrap_or("???"), + Self::File(filename) => filename.to_str().unwrap_or("_"), Self::REPL | Self::Pipe(_) => "stdin", Self::Str(_) => "string", Self::Dummy => "dummy", @@ -56,10 +56,7 @@ impl Input { pub fn filename(&self) -> &str { match self { - Self::File(filename) => filename - .file_name() - .and_then(|f| f.to_str()) - .unwrap_or("???"), + Self::File(filename) => filename.file_name().and_then(|f| f.to_str()).unwrap_or("_"), Self::REPL | Self::Pipe(_) => "stdin", Self::Str(_) => "string", Self::Dummy => "dummy", @@ -266,6 +263,32 @@ impl ErgConfig { } } + pub fn dump_filename(&self) -> String { + if let Some(output) = &self.output_dir { + format!("{output}/{}", self.input.filename()) + } else { + self.input.filename().to_string() + } + } + + pub fn dump_pyc_path(&self) -> String { + let dump_path = self.dump_path(); + if dump_path.ends_with(".er") { + dump_path.replace(".er", ".pyc") + } else { + dump_path + ".pyc" + } + } + + pub fn dump_pyc_filename(&self) -> String { + let dump_filename = self.dump_filename(); + if dump_filename.ends_with(".er") { + dump_filename.replace(".er", ".pyc") + } else { + dump_filename + ".pyc" + } + } + pub fn inherit(&self, path: PathBuf) -> Self { Self { module: Box::leak(path.to_str().unwrap().to_string().into_boxed_str()), diff --git a/compiler/erg_compiler/compile.rs b/compiler/erg_compiler/compile.rs index daf89106..1dd874bb 100644 --- a/compiler/erg_compiler/compile.rs +++ b/compiler/erg_compiler/compile.rs @@ -147,7 +147,7 @@ impl Runnable for Compiler { } fn exec(&mut self) -> Result { - let path = self.cfg.dump_path().replace(".er", ".pyc"); + let path = self.cfg.dump_pyc_path(); let warns = self .compile_and_dump_as_pyc(path, self.input().read(), "exec") .map_err(|eart| { diff --git a/src/dummy.rs b/src/dummy.rs index 0f0d1d4a..3ec485f9 100644 --- a/src/dummy.rs +++ b/src/dummy.rs @@ -121,14 +121,7 @@ impl Runnable for DummyVM { fn exec(&mut self) -> Result { // Parallel execution is not possible without dumping with a unique file name. - let filename = self - .cfg() - .input - .full_path() - .split('/') - .last() - .unwrap() - .replace(".er", ".pyc"); + let filename = self.cfg().dump_pyc_filename(); let warns = self .compiler .compile_and_dump_as_pyc(&filename, self.input().read(), "exec")