mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-03 14:04:33 +00:00
Partially fi x #296
This commit is contained in:
parent
261927e0f9
commit
1cc17bdd5a
3 changed files with 31 additions and 15 deletions
|
@ -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(_) => "<stdin>",
|
||||
Self::Str(_) => "<string>",
|
||||
Self::Dummy => "<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()),
|
||||
|
|
|
@ -147,7 +147,7 @@ impl Runnable for Compiler {
|
|||
}
|
||||
|
||||
fn exec(&mut self) -> Result<i32, Self::Errs> {
|
||||
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| {
|
||||
|
|
|
@ -121,14 +121,7 @@ impl Runnable for DummyVM {
|
|||
|
||||
fn exec(&mut self) -> Result<i32, Self::Errs> {
|
||||
// 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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue