mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-03 02:13:11 +00:00
parent
846aac89a7
commit
fa5bb4f615
7 changed files with 80 additions and 90 deletions
|
@ -2,11 +2,9 @@ extern crate erg_common;
|
|||
extern crate erg_compiler;
|
||||
extern crate erg_parser;
|
||||
|
||||
use std::process;
|
||||
|
||||
use erg_common::config::{ErgConfig, ErgMode::*};
|
||||
use erg_common::spawn::exec_new_thread;
|
||||
use erg_common::traits::Runnable;
|
||||
use erg_common::traits::{ExitStatus, Runnable};
|
||||
|
||||
use erg_compiler::build_hir::HIRBuilder;
|
||||
use erg_compiler::lower::ASTLowerer;
|
||||
|
@ -19,33 +17,20 @@ use erg_parser::ParserRunner;
|
|||
|
||||
fn run() {
|
||||
let cfg = ErgConfig::parse();
|
||||
match cfg.mode {
|
||||
Lex => {
|
||||
LexerRunner::run(cfg);
|
||||
}
|
||||
Parse => {
|
||||
ParserRunner::run(cfg);
|
||||
}
|
||||
TypeCheck => {
|
||||
ASTLowerer::run(cfg);
|
||||
}
|
||||
FullCheck => {
|
||||
HIRBuilder::run(cfg);
|
||||
}
|
||||
Transpile => {
|
||||
Transpiler::run(cfg);
|
||||
}
|
||||
Compile | Execute => {
|
||||
Compiler::run(cfg);
|
||||
}
|
||||
Read => {
|
||||
Deserializer::run(cfg);
|
||||
}
|
||||
let stat = match cfg.mode {
|
||||
Lex => LexerRunner::run(cfg),
|
||||
Parse => ParserRunner::run(cfg),
|
||||
TypeCheck => ASTLowerer::run(cfg),
|
||||
FullCheck => HIRBuilder::run(cfg),
|
||||
Transpile => Transpiler::run(cfg),
|
||||
Compile | Execute => Compiler::run(cfg),
|
||||
Read => Deserializer::run(cfg),
|
||||
other => {
|
||||
println!("invalid mode: {other}");
|
||||
process::exit(1);
|
||||
ExitStatus::ERR1
|
||||
}
|
||||
}
|
||||
};
|
||||
std::process::exit(stat.code);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
//! バイトコードからオブジェクトを復元する
|
||||
use std::process;
|
||||
use std::string::FromUtf8Error;
|
||||
|
||||
use erg_common::cache::CacheSet;
|
||||
|
@ -8,6 +7,7 @@ use erg_common::dict::Dict;
|
|||
use erg_common::error::{ErrorCore, ErrorKind, Location, SubMessage};
|
||||
use erg_common::python_util::PythonVersion;
|
||||
use erg_common::serialize::DataTypePrefix;
|
||||
use erg_common::traits::ExitStatus;
|
||||
use erg_common::{fn_name, switch_lang};
|
||||
use erg_common::{RcArray, Str};
|
||||
|
||||
|
@ -110,21 +110,23 @@ impl Deserializer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn run(cfg: ErgConfig) {
|
||||
pub fn run(cfg: ErgConfig) -> ExitStatus {
|
||||
let Input::File(filename) = cfg.input else {
|
||||
eprintln!("{:?} is not a filename", cfg.input);
|
||||
process::exit(1);
|
||||
return ExitStatus::ERR1;
|
||||
};
|
||||
match CodeObj::from_pyc(&filename) {
|
||||
Ok(codeobj) => {
|
||||
println!("{}", codeobj.code_info(None));
|
||||
ExitStatus::OK
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!(
|
||||
"failed to deserialize {}: {}",
|
||||
filename.to_string_lossy(),
|
||||
e.desc
|
||||
)
|
||||
);
|
||||
ExitStatus::ERR1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue