diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..573b15e --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,11 @@ +[alias] +r = "run" +rd = "run --features debug" +b = "build" +bd = "build --features debug" +r_re = "run --release" +rd_re = "run --features debug --release" +b_re = "build --release" +bd_re = "build --features debug --release" +i = "install --path ." +di = "install --path . --debug --features debug" diff --git a/Cargo.lock b/Cargo.lock index 6034fe0..f019027 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -172,9 +172,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cc" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" [[package]] name = "cfg-if" @@ -246,14 +246,14 @@ dependencies = [ [[package]] name = "either" -version = "1.8.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "els" version = "0.1.15" -source = "git+https://github.com/erg-lang/erg?branch=main#4b08fd21a286916b0f3e3499aec2b9299082516d" +source = "git+https://github.com/erg-lang/erg?branch=main#da6483308ff49b1ca62157cb60b4805424fe1ff7" dependencies = [ "erg_common", "erg_compiler", @@ -274,7 +274,7 @@ dependencies = [ [[package]] name = "erg_common" version = "0.6.3" -source = "git+https://github.com/erg-lang/erg?branch=main#4b08fd21a286916b0f3e3499aec2b9299082516d" +source = "git+https://github.com/erg-lang/erg?branch=main#da6483308ff49b1ca62157cb60b4805424fe1ff7" dependencies = [ "backtrace-on-stack-overflow", "hermit-abi", @@ -285,7 +285,7 @@ dependencies = [ [[package]] name = "erg_compiler" version = "0.6.3" -source = "git+https://github.com/erg-lang/erg?branch=main#4b08fd21a286916b0f3e3499aec2b9299082516d" +source = "git+https://github.com/erg-lang/erg?branch=main#da6483308ff49b1ca62157cb60b4805424fe1ff7" dependencies = [ "erg_common", "erg_parser", @@ -294,7 +294,7 @@ dependencies = [ [[package]] name = "erg_parser" version = "0.6.3" -source = "git+https://github.com/erg-lang/erg?branch=main#4b08fd21a286916b0f3e3499aec2b9299082516d" +source = "git+https://github.com/erg-lang/erg?branch=main#da6483308ff49b1ca62157cb60b4805424fe1ff7" dependencies = [ "erg_common", "unicode-xid 0.2.4", @@ -947,9 +947,9 @@ dependencies = [ [[package]] name = "tinyvec_macros" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "typenum" diff --git a/crates/py2erg/convert.rs b/crates/py2erg/convert.rs index 4ea7c5e..73ee458 100644 --- a/crates/py2erg/convert.rs +++ b/crates/py2erg/convert.rs @@ -210,7 +210,7 @@ pub enum ShadowingMode { /// /// would be converted as follows. This is a mistake. /// -/// ``` +/// ```python /// i = 1 /// i = i2 + 1 /// ``` @@ -453,7 +453,7 @@ impl ASTConverter { let method = tmp_expr.clone().attr_expr( self.convert_ident("__Tuple_getitem__".to_string(), expr.location), ); - let args = Args::new(vec![PosArg::new(Expr::Lit(index))], vec![], None); + let args = Args::new(vec![PosArg::new(Expr::Lit(index))], None, vec![], None); let tuple_acc = method.call_expr(args); let body = DefBody::new(EQUAL, Block::new(vec![tuple_acc]), DefId(0)); let def = Expr::Def(Def::new(sig, body)); @@ -616,13 +616,12 @@ impl ASTConverter { let sig = LambdaSignature::new(params, None, TypeBoundSpecs::empty()); let else_body = Lambda::new(sig, Token::DUMMY, Block::new(vec![else_block]), DefId(0)); - let args = Args::new( + let args = Args::pos_only( vec![ PosArg::new(test), PosArg::new(Expr::Lambda(body)), PosArg::new(Expr::Lambda(else_body)), ], - vec![], None, ); if_acc.call_expr(args) @@ -637,7 +636,7 @@ impl ASTConverter { .into_iter() .map(|ex| PosArg::new(self.convert_expr(ex))) .collect::>(); - let args = Args::new(pos_args, vec![], None); + let args = Args::pos_only(pos_args, None); function.call_expr(args) } ExpressionType::Binop { a, op, b } => { @@ -713,7 +712,7 @@ impl ASTConverter { .into_iter() .map(|ex| PosArg::new(self.convert_expr(ex))) .collect::>(); - let elems = Args::new(elements, vec![], None); + let elems = Args::pos_only(elements, None); Expr::Array(Array::Normal(NormalArray::new(l_sqbr, r_sqbr, elems))) // Self::mutate_expr(arr) } @@ -724,7 +723,7 @@ impl ASTConverter { .into_iter() .map(|ex| PosArg::new(self.convert_expr(ex))) .collect::>(); - let elems = Args::new(elements, vec![], None); + let elems = Args::pos_only(elements, None); Expr::Set(Set::Normal(NormalSet::new(l_brace, r_brace, elems))) // Self::mutate_expr(set) } @@ -752,14 +751,14 @@ impl ASTConverter { .into_iter() .map(|ex| PosArg::new(self.convert_expr(ex))) .collect::>(); - let elems = Args::new(elements, vec![], None); + let elems = Args::pos_only(elements, None); Expr::Tuple(Tuple::Normal(NormalTuple::new(elems))) } ExpressionType::Subscript { a, b } => { let obj = self.convert_expr(*a); let method = obj.attr_expr(self.convert_ident("__getitem__".to_string(), expr.location)); - let args = Args::new(vec![PosArg::new(self.convert_expr(*b))], vec![], None); + let args = Args::pos_only(vec![PosArg::new(self.convert_expr(*b))], None); method.call_expr(args) } _other => { @@ -1003,7 +1002,7 @@ impl ASTConverter { } else { vec![] }; - let args = Args::new(pos_args, vec![], None); + let args = Args::pos_only(pos_args, None); let class_acc = Expr::Accessor(Accessor::Ident( self.convert_ident("Class".to_string(), loc), )); @@ -1125,7 +1124,7 @@ impl ASTConverter { stmt.location, )); let args = - Args::new(vec![PosArg::new(Expr::Lit(index))], vec![], None); + Args::pos_only(vec![PosArg::new(Expr::Lit(index))], None); let tuple_acc = method.call_expr(args); let body = DefBody::new(EQUAL, Block::new(vec![tuple_acc]), DefId(0)); @@ -1270,9 +1269,8 @@ impl ASTConverter { let block = self.convert_for_body(Some(*target), body); let for_ident = self.convert_ident("for".to_string(), stmt.location); let for_acc = Expr::Accessor(Accessor::Ident(for_ident)); - for_acc.call_expr(Args::new( + for_acc.call_expr(Args::pos_only( vec![PosArg::new(iter), PosArg::new(Expr::Lambda(block))], - vec![], None, )) } @@ -1288,9 +1286,8 @@ impl ASTConverter { let body = Lambda::new(empty_sig, Token::DUMMY, block, DefId(0)); let while_ident = self.convert_ident("while".to_string(), stmt.location); let while_acc = Expr::Accessor(Accessor::Ident(while_ident)); - while_acc.call_expr(Args::new( + while_acc.call_expr(Args::pos_only( vec![PosArg::new(test), PosArg::new(Expr::Lambda(body))], - vec![], None, )) } @@ -1306,20 +1303,18 @@ impl ASTConverter { let else_block = self.convert_block(orelse, BlockKind::If); let sig = LambdaSignature::new(params, None, TypeBoundSpecs::empty()); let else_body = Lambda::new(sig, Token::DUMMY, else_block, DefId(0)); - let args = Args::new( + let args = Args::pos_only( vec![ PosArg::new(test), PosArg::new(Expr::Lambda(body)), PosArg::new(Expr::Lambda(else_body)), ], - vec![], None, ); if_acc.call_expr(args) } else { - let args = Args::new( + let args = Args::pos_only( vec![PosArg::new(test), PosArg::new(Expr::Lambda(body))], - vec![], None, ); if_acc.call_expr(args) @@ -1337,16 +1332,16 @@ impl ASTConverter { )); let return_acc = self.convert_ident("return".to_string(), stmt.location); let return_acc = Expr::Accessor(Accessor::attr(func_acc, return_acc)); - return_acc.call_expr(Args::new(vec![PosArg::new(value)], vec![], None)) + return_acc.call_expr(Args::pos_only(vec![PosArg::new(value)], None)) } } StatementType::Assert { test, msg } => { let test = self.convert_expr(test); let args = if let Some(msg) = msg { let msg = self.convert_expr(msg); - Args::new(vec![PosArg::new(test), PosArg::new(msg)], vec![], None) + Args::pos_only(vec![PosArg::new(test), PosArg::new(msg)], None) } else { - Args::new(vec![PosArg::new(test)], vec![], None) + Args::pos_only(vec![PosArg::new(test)], None) }; let assert_acc = Expr::Accessor(Accessor::Ident( self.convert_ident("assert".to_string(), stmt.location), @@ -1366,7 +1361,7 @@ impl ASTConverter { stmt.location.row() as u32, stmt.location.column() as u32 - 1, ))); - let args = Args::new(vec![PosArg::new(mod_name)], vec![], None); + let args = Args::pos_only(vec![PosArg::new(mod_name)], None); let call = import_acc.call_expr(args); let def = if let Some(alias) = name.alias { self.register_name_info(&alias, NameKind::Variable); @@ -1412,7 +1407,7 @@ impl ASTConverter { stmt.location.row() as u32, stmt.location.column() as u32 - 1, ))); - let args = Args::new(vec![PosArg::new(mod_name)], vec![], None); + let args = Args::new(vec![PosArg::new(mod_name)], None, vec![], None); let call = import_acc.call_expr(args); self.register_name_info(module.as_ref().unwrap(), NameKind::Variable); let mod_ident = self.convert_ident(module.unwrap(), stmt.location); @@ -1487,9 +1482,8 @@ impl ASTConverter { let body = self.convert_for_body(item.optional_vars, body); let with_ident = self.convert_ident("with".to_string(), stmt.location); let with_acc = Expr::Accessor(Accessor::Ident(with_ident)); - with_acc.call_expr(Args::new( + with_acc.call_expr(Args::pos_only( vec![PosArg::new(context_expr), PosArg::new(Expr::Lambda(body))], - vec![], None, )) } diff --git a/src/analyze.rs b/src/analyze.rs index fbac053..77c5fa7 100644 --- a/src/analyze.rs +++ b/src/analyze.rs @@ -1,6 +1,7 @@ use erg_common::config::ErgConfig; use erg_common::error::{ErrorCore, ErrorKind, MultiErrorDisplay}; -use erg_common::style::{BLUE, GREEN, RED, RESET, YELLOW}; +use erg_common::style::colors::{BLUE, GREEN, RED, YELLOW}; +use erg_common::style::RESET; use erg_common::traits::{Runnable, Stream}; use erg_common::Str; use erg_compiler::artifact::{BuildRunnable, Buildable, CompleteArtifact, IncompleteArtifact}; @@ -56,7 +57,7 @@ impl Runnable for PythonAnalyzer { impl Buildable for PythonAnalyzer { fn inherit(cfg: ErgConfig, shared: SharedCompilerResource) -> Self { - let mod_name = Str::rc(cfg.input.file_stem()); + let mod_name = Str::rc(&cfg.input.file_stem()); Self { cfg: cfg.copy(), checker: ASTLowerer::new_with_cache(cfg, mod_name, shared), @@ -104,7 +105,7 @@ impl PythonAnalyzer { }; let converter = py2erg::ASTConverter::new(self.cfg.copy(), shadowing); let IncompleteArtifact{ object: Some(erg_module), mut errors, mut warns } = converter.convert_program(py_program) else { unreachable!() }; - let erg_ast = AST::new(erg_common::Str::rc(filename), erg_module); + let erg_ast = AST::new(erg_common::Str::rc(&filename), erg_module); erg_common::log!("AST:\n{erg_ast}"); match self.checker.lower(erg_ast, mode) { Ok(mut artifact) => { diff --git a/src/main.rs b/src/main.rs index 63bedca..d218d67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,7 @@ pub fn parse_args() -> ErgConfig { break; } "-c" | "--code" => { - cfg.input = Input::Str(args.next().expect("the value of `-c` is not passed")); + cfg.input = Input::str(args.next().expect("the value of `-c` is not passed")); } "--server" => { cfg.mode = ErgMode::LanguageServer; @@ -58,7 +58,7 @@ For more information try `pylyzer --help`" _ => { cfg.input = Input::File( PathBuf::from_str(&arg[..]) - .unwrap_or_else(|_| panic!("invalid file path: {}", arg)), + .unwrap_or_else(|_| panic!("invalid file path: {arg}")), ); if let Some("--") = args.next().as_ref().map(|s| &s[..]) { for arg in args {